PDA

View Full Version : [CLOSED] How can I change a grid's selectionmodel after grid has been rendered



jchau
Jan 18, 2013, 10:30 PM
I have a grid in readonly mode with rowselection. On a button click, I need to make grid editable and turn on cellediting plugin and change selectionmode to cellselection. I got the cellediting part done. But I can't seem to change selectionmode to cellselection.

jchau
Jan 19, 2013, 1:41 AM
Please mark as closed. I realized u can have cellediting plugin with rowselection. But there are issues with tabbing and entering so i will create a separate thread.

Baidaly
Jan 19, 2013, 2:54 AM
Hello!

Take a look at the following example:



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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Store1.DataSource = this.Data;
this.Store1.DataBind();
}
}

private object[] Data
{
get
{
return new object[]
{
new object[] { "3m Co", 71.72, 0.02, 0.03, "9/1 12:00am" },
new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
new object[] { "American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" }
};
}
}

protected void ChangeSelectionModel(object sender, DirectEventArgs e)
{
((Ext.Net.Button)sender).Disabled = true;

this.GridPanel1.SelectionModel.Clear();
this.GridPanel1.SelectionModel.Add(new CellSelectionModel());
this.GridPanel1.Render();
}

</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Simple Array Grid - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />

<style>
.x-grid-row-over .x-grid-cell-inner {
font-weight : bold;
}
</style>

<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>
<ext:ResourceManager runat="server" />

<ext:Button runat="server" OnDirectClick="ChangeSelectionModel" Text="Change selection model"></ext:Button>

<h1>Simple Array Grid</h1>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="company" />
<ext:ModelField Name="price" Type="Float" />
<ext:ModelField Name="change" Type="Float" />
<ext:ModelField Name="pctChange" Type="Float" />
<ext:ModelField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
</Fields>
</ext:Model>
</Model>
</ext:Store>

<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Array Grid"
Width="600"
StoreID="Store1"
Height="350">
<ColumnModel>
<Columns>
<ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
<ext:Column runat="server" Text="Price" DataIndex="price">
<Renderer Format="UsMoney" />
</ext:Column>
<ext:Column runat="server" Text="Change" DataIndex="change">
<Renderer Fn="change" />
</ext:Column>
<ext:Column runat="server" Text="Change" DataIndex="pctChange">
<Renderer Fn="pctChange" />
</ext:Column>
<ext:DateColumn runat="server" Text="Last Updated" DataIndex="lastChange" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" />
</SelectionModel>
</ext:GridPanel>
</body>
</html>