PDA

View Full Version : [CLOSED] Problem with Checkbox Selection in GridPanel



opendat2000
Aug 03, 2016, 10:54 PM
Hi Community !

Please check the code sample below:




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

<%@ Import Namespace="System.Collections.Generic" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Store1.DataSource = new List<Company>
{
new Company(0, "3m Co", 71.72, 0.02, 0.03),
new Company(1, "Alcoa Inc", 29.01, 0.42, 1.47),
new Company(2, "Altria Group Inc", 83.81, 0.28, 0.34),
new Company(3, "American Express Company", 52.55, 0.01, 0.02),
new Company(4, "American International Group, Inc.", 64.13, 0.31, 0.49),
new Company(5, "AT&T Inc.", 31.61, -0.48, -1.54),
new Company(6, "Boeing Co.", 75.43, 0.53, 0.71),
new Company(7, "Caterpillar Inc.", 67.27, 0.92, 1.39),
new Company(8, "Citigroup, Inc.", 49.37, 0.02, 0.04),
new Company(9, "E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28),
new Company(10, "Exxon Mobil Corp", 68.1, -0.43, -0.64),
};

this.Store1.DataBind();
}
}

protected void Button1_Click(object sender, DirectEventArgs e)
{
StringBuilder result = new StringBuilder();

result.Append("<b>Selected Rows (ids)</b></br /><ul>");
RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel;

foreach (SelectedRow row in sm.SelectedRows)
{
result.Append("<li>" + row.RecordID + "</li>");
}

result.Append("</ul>");
this.Label1.Html = result.ToString();
}

public class Company
{
public Company(int id, string name, double price, double change, double pctChange)
{
this.ID = id;
this.Name = name;
this.Price = price;
this.Change = change;
this.PctChange = pctChange;
}

public int ID { get; set; }
public string Name { get; set; }
public double Price { get;set; }
public double Change { get;set; }
public double PctChange { get;set; }
}
</script>

<!DOCTYPE html>

<html>

<head id="Head1" runat="server">
<title>GridPanel with Checkbox Selection Model - Ext.NET Examples</title>

<script>
var template = '<span style="color:{0};">{1}</span>';

var change = function (value) {
return Ext.String.format(template, (value > 0) ? "green" : "red", value);
};

var pctChange = function (value) {
return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
};
</script>
</head>

<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<h1>GridPanel with Checkbox Selection Model</h1>

<ext:GridPanel ID="GridPanel1" runat="server"
Title="Company List"
Collapsible="true"
Width="600">
<Store>
<ext:Store ID="Store1" runat="server" PageSize="10">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="ID, Name">
<Fields>
<ext:ModelField Name="ID" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Price" />
<ext:ModelField Name="Change" />
<ext:ModelField Name="PctChange" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1"
runat="server"
Text="Company"
Width="160"
DataIndex="Name"
Resizable="false"
MenuDisabled="true"
Flex="1" />

<ext:Column ID="Column2" runat="server" Text="Price" Width="75" DataIndex="Price">
<Renderer Format="UsMoney" />
</ext:Column>

<ext:Column ID="Column3" runat="server" Text="Change" Width="75" DataIndex="Change">
<Renderer Fn="change" />
</ext:Column>

<ext:Column ID="Column4" runat="server" Text="Change" Width="75" DataIndex="PctChange">
<Renderer Fn="pctChange" />
</ext:Column>
</Columns>
</ColumnModel>

<SelectionModel>
<ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" Mode="Multi" />
</SelectionModel>

<BottomBar>
<ext:PagingToolbar ID="PagingToolbar1" runat="server" DisplayInfo="false" HideRefresh="true">
<Items>
<ext:Button ID="Button1" runat="server" Text="Submit Selected Records" StandOut="true">
<DirectEvents>
<Click OnEvent="Button1_Click">
<EventMask ShowMask="true" />
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:PagingToolbar>
</BottomBar>

</ext:GridPanel>

<div style="width:590px; border:1px solid gray; padding:5px;">
<ext:Label ID="Label1" runat="server" />
</div>
</form>
</body>
</html>



In this code, when i try to recover "Id Property" from Control Store, gave me a wrong value, it should be because "ID Property" have two columns,
can you help me with this code so that the returned values be correct.

I accept suggestions ideas or comments

fabricio.murta
Aug 04, 2016, 1:36 AM
Hello!

For this I'm afraid you'll need to provide a single column, maybe, with the concatenated value of the columns you want to use as composite primary key.

There are already at least one forum discussion on this: IDProperty: set multiple key fields (http://forums.ext.net/showthread.php?23168).

I hope this helps!

opendat2000
Aug 05, 2016, 1:27 PM
Hi Fabricio,

Thanks, please close the thread.

Saludos
Mauricio.