PDA

View Full Version : [CLOSED] Check column issue



mohan.bizbites
Nov 28, 2013, 12:47 PM
Hello Team ,
in grid panel , we need Yes /No instead of true/false for Boolean column (we have a requirement to display Yes/No when group by this field ). for this we have written in the Modelfield render of store as follow

function boolConvert(value) {
if (value == true) {
return 'Yes';
}
if (value == false) {
return 'No';
}


}

we are getting Yes/No ,but all check columns are checked in the grid . Please give us a solution for this
here is the sample code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PanelTest.aspx.cs" Inherits="Cresent.WorkSafeExt.PanelTest" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.GridPanel1.Store.Primary.DataSource = new object[]
{
new object[] { true, DateTime.Now, 1 },
new object[] { false, DateTime.Now.AddDays(-1), 2 },
new object[] { true, DateTime.Now.AddDays(-2), 3 },
new object[] { false, DateTime.Now.AddDays(-3), 4 },
new object[] { true, DateTime.Now.AddDays(-4), 5 }
};


this.GridPanel1.Store.Primary.DataBind();
}
}
</script>
<script type="text/javascript">
function boolConvert(value) {
if (value == true) {
return 'Yes';
}
if (value == false) {
return 'No';
}


}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<div>
<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Column Variations"
DisableSelection="true"
Width="600"
Height="350">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="booleanCol" Type="Boolean">
<Convert Fn="boolConvert"></Convert>
</ext:ModelField>
<ext:ModelField Name="date" Type="Date"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:CheckColumn ID="CheckColumn1" runat="server" DataIndex="booleanCol" Text="Check" />
<ext:Column ID="datecolumn" DataIndex="date" runat="server" Text="Date"></ext:Column>
</Columns>
</ColumnModel>
<Features>
<ext:Grouping ID="GroupingHira" runat="server" HideGroupedHeader="true" StartCollapsed="false"
GroupHeaderTplString='{columnName}: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'>
</ext:Grouping>
</Features>
<View>
<ext:GridView ID="GridView1" runat="server" StripeRows="true" />
</View>
</ext:GridPanel>
</div>
</form>
</body>
</html>


Thanks in Advance

Daniil
Nov 28, 2013, 12:57 PM
Hi Mohan,

A ModelField's Convert is not a solution, because you are getting strings in a record, but a CheckColumn is supposed to be used with boolean values only.

A BooleanColumn looks better for your requirement.

<ext:BooleanColumn
runat="server"
DataIndex="booleanCol"
Text="Check"
TrueText="Yes"
FalseText="No" />

mohan.bizbites
Nov 28, 2013, 1:10 PM
Thanks for your replay Daniil,

Here we want to display check box column only , Boolean column returns text (yes/no) .

Daniil
Nov 28, 2013, 1:49 PM
Hmm, if I correctly understand the requirement, please try this:

GroupHeaderTplString='{columnName}: {[values.groupValue ? "Yes" : "No"]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'

Remove the ModelField's Convert as well.

mohan.bizbites
Dec 02, 2013, 4:58 AM
Hi Daniil,

GroupHeaderTplString='{columnName}: {[values.groupValue ? "Yes" : "No"]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'

This solution is working fine but for every grouping result showing for Yes or no
7314

Daniil
Dec 02, 2013, 5:44 AM
Please replace the GroupHeaderTpl with:

<ext:Grouping runat="server">
<GroupHeaderTpl runat="server">
<Html>
{columnName}: {name:this.getValue(values)} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})
</Html>
<Functions>
<ext:JFunction
Name="getValue"
Args="name,values"
Handler="if (values.columnName === 'Check') {
return values.groupValue ? 'Yes' : 'No';
} else {
return values.name;
}" />
</Functions>
</GroupHeaderTpl>
</ext:Grouping>