PDA

View Full Version : [CLOSED] NumberColumn is not showing 1 decimal values ,if there is Render funcation for the gridPanel



praveencat123
Sep 07, 2015, 7:16 AM
HI Daniil


NumberColumn is not showing 1 decimal values ,if there is Render function for the gridPanel

Please find the code and screenshot

<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Ext.Net" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
try
{
BindRecords();
}
catch (System.Data.SqlClient.SqlException ex)
{
string strin = ex.ToString();
}
}
}

public void BindRecords()
{
DataTable dtSpiCpi = new DataTable();
dtSpiCpi.Locale = System.Globalization.CultureInfo.InvariantCulture;
dtSpiCpi.Columns.Add("Type", typeof(string));
dtSpiCpi.Columns.Add("Jan", typeof(decimal));
dtSpiCpi.Columns.Add("Feb", typeof(decimal));
dtSpiCpi.Columns.Add("Mar", typeof(decimal));
dtSpiCpi.Columns.Add("Apr", typeof(decimal));

DataRow objRow = null;

for (int index = 1; index <= 12; index++)
{
objRow = dtSpiCpi.NewRow();
objRow["Type"] = index + "Jan15";

if (index < 3)
{
//objRow["Jan"] = Convert.ToDecimal("2.50");
objRow["Feb"] = Convert.ToDecimal("2.10");
objRow["Mar"] = Convert.ToDecimal("2.00");
objRow["Apr"] = Convert.ToDecimal("1.0");
}
else if (index < 5)
{
objRow["Jan"] = Convert.ToDecimal("1.0");
objRow["Feb"] = Convert.ToDecimal("2.0");
objRow["Mar"] = Convert.ToDecimal("3.0");
objRow["Apr"] = Convert.ToDecimal("4.0");
}
else if (index < 7)
{
objRow["Mar"] = Convert.ToDecimal("9.0");
objRow["Jan"] = Convert.ToDecimal("3.0");
objRow["Feb"] = Convert.ToDecimal("2.0");
objRow["Apr"] = Convert.ToDecimal("3.0");

}
else
{
objRow["Jan"] = Convert.ToDecimal("4.9");
objRow["Feb"] = Convert.ToDecimal("3.0");
objRow["Mar"] = Convert.ToDecimal("2.0");
objRow["Apr"] = Convert.ToDecimal("1.0");

}
dtSpiCpi.Rows.Add(objRow);
}

storeSpiCpi.RemoveAll();
storeSpiCpi.DataSource = dtSpiCpi;
storeSpiCpi.DataBind();

}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Submit MultiSelect Values - Ext.NET Examples</title>
<script type="text/javascript" language="javascript">

function ManpowerAllocation_Renderer(columnValue, columnValueCls, record, rowIndex, columnNumber) {

var columnIndex = columnValueCls.columnIndex;
var forecolor;
var backGroundcolor;

switch (columnIndex) {
case 13:
if (rowIndex == 6) {
backGroundcolor = '#FFFFFF';
}
else {
backGroundcolor = '#ededee';
}
break;
default:
break;

var cssString = "background-color:{0};text-align:right;font: bold 8.5pt Arial, verdana, helvetica;";
cssString = String.format(cssString, backGroundcolor, forecolor);
columnValueCls.style = cssString;

}
return columnValue;
}


</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" Namespace="" />
<table border="1">
<tr>
<td>
<ext:GridPanel ID="grdFillRatePercentage" runat="server" Width="500" Height="350" Flex="1" AutoScroll="true" EnableColumnMove="false">
<Store>
<ext:Store ID="storeSpiCpi" runat="server">
<Model>
<ext:Model ID="Model38" runat="server">
<Fields>
<ext:ModelField Name="Type" />
<ext:ModelField Name="Jan" />
<ext:ModelField Name="Feb" />
<ext:ModelField Name="Mar" />
<ext:ModelField Name="Apr" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel2" runat="server">
<Columns>
<ext:Column ID="Column70" Sortable="false" runat="server" Text="" Resizable="false"
MenuDisabled="true">
<Columns>
<ext:Column Height="20px" ID="Column88" runat="server" DataIndex="Type" Text="Type" Width="160" MenuDisabled="true" Sortable="false" Resizable="false" TdCls="boldClass" />
<ext:NumberColumn Height="20px" ID="Column89" runat="server" Text="Jan" DataIndex="Jan" Width="80" Resizable="true" Sortable="false"
MenuDisabled="true" Align="Right" Format="0.0">
<Renderer Fn="ManpowerAllocation_Renderer" />
</ext:NumberColumn>
<ext:Column Height="20px" ID="Column90" Text="Feb" runat="server" DataIndex="Feb" Width="80" Resizable="true" Sortable="false"
MenuDisabled="true" Align="Right">
</ext:Column>
<ext:Column ID="Column91" runat="server" Text="Mar" DataIndex="Mar" Width="80" Resizable="true" Sortable="false"
MenuDisabled="true" Align="Right">
</ext:Column>
<ext:Column ID="Column92" runat="server" Text="Apr" DataIndex="Apr" Width="80" Resizable="true" Sortable="false"
MenuDisabled="true" Align="Right">
</ext:Column>
</Columns>
</ext:Column>
</Columns>
</ColumnModel>
<View>
<ext:GridView ID="grdViewFillRatePercentage" runat="server" StripeRows="false" TrackOver="false" />
</View>
</ext:GridPanel>
</td>
</tr>
</table>
</form>
</body>
</html>

Daniil
Sep 07, 2015, 9:34 AM
Hi @praveencat123,

A NumberColumn doesn't support a custom Renderer, because it uses its own custom Renderer which is defined internally.

You can switch to a regular Column and replace

return columnValue; with

return Ext.util.Format.number(columnValue, "0.0");
in the Renderer function.

praveencat123
Sep 07, 2015, 3:03 PM
Thanks daniil...Its working