Sep 10, 2015, 3:48 PM
Seems another issue has arrived from the selection. It appears that using the command select does not fill the selection model.
I have included the test case and using "[DirectMethod]" as it is a server side method that I am using in my actual code. Working test case below uses the same data xml as the previous test case.
I have included the test case and using "[DirectMethod]" as it is a server side method that I am using in my actual code. Working test case below uses the same data xml as the previous test case.
<%@ 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)
{
XElement document = XElement.Load(Server.MapPath("Data.xml"));
IEnumerable<object> query = from g in document.Elements("Monitor")
select new
{
DESCRIPTION = g.Attribute("DESCRIPTION") != null ? g.Attribute("DESCRIPTION").Value : "",
CATEGORY = g.Attribute("CATEGORY") != null ? g.Attribute("CATEGORY").Value : "",
MONITORID = g.Attribute("MONITORID") != null ? g.Attribute("MONITORID").Value : ""
};
this.storeMonitors.DataSource = query;
this.storeMonitors.DataBind();
}
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<ext:XScript runat="server">
<script>
var onGroupCommand = function (column, command, group) {
Ext.getBody().mask('Please wait while your selection is made.');
Ext.defer(function () { SelectDeselectRows(column, command, group); Ext.getBody().unmask(); }, 10);
};
function SelectDeselectRows(column, command, group) {
var selModel,
isSelected;
if (command === 'SelectMonitor') {
selModel = column.grid.getSelectionModel();
isSelected = selModel.isSelected(group.children[0]);
selModel.suspendChanges();
if (!isSelected) {
selModel.select(group.children, true, true);
} else {
selModel.deselect(group.children, true, true);
};
selModel.resumeChanges();
}
}
</script>
</ext:XScript>
<script runat="server">
[DirectMethod]
public void btnSaveMonitors_Click()
{
var smMonitors = gpMonitors.GetSelectionModel() as RowSelectionModel;
var cnt = smMonitors.SelectedRows.Count();
X.Msg.Show(new MessageBoxConfig
{
Title = "Selected Records",
Message = "Total Records: " + cnt,
Buttons = MessageBox.Button.OK
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<div>
<ext:Panel ID="pnlMonitors" runat="server" Title="Monitors" Border="false" MaxHeight="600" BodyPadding="6" Layout="FormLayout" AutoScroll="true">
<TopBar>
<ext:Toolbar runat="server" Flat="true">
<Items>
<ext:Button ID="btnSaveMonitors" Text="Save Monitors" runat="server" Icon="DiskBlack">
<Listeners>
<Click Handler="#{DirectMethods}.btnSaveMonitors_Click();"></Click>
</Listeners>
<ToolTips>
<ext:ToolTip runat="server" Html="Save Monitors" />
</ToolTips>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:GridPanel HideHeaders="False" Scroll="Vertical" AutoScroll="true"
ID="gpMonitors"
runat="server"
MinHeight="200">
<Store>
<ext:Store ID="storeMonitors" runat="server" GroupField="CATEGORY">
<Model>
<ext:Model runat="server" IDProperty="MONITORID">
<Fields>
<ext:ModelField Name="MONITORID" />
<ext:ModelField Name="DESCRIPTION" />
<ext:ModelField Name="CATEGORY" />
<ext:ModelField Name="SELECTED" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Hidden="True" DataIndex="MONITORID" Text="MONITORID" Flex="1" />
<ext:Column runat="server" DataIndex="DESCRIPTION" Text="DESCRIPTION" Flex="4" />
<ext:CommandColumn ID="CommandColumn1" runat="server" Hidden="true">
<GroupCommands>
<ext:GridCommand Icon="TableRow" CommandName="SelectMonitor">
<ToolTip Title="Select/DeSelect" Text="Select/DeSelect all rows of the group" />
</ext:GridCommand>
</GroupCommands>
<Listeners>
<GroupCommand Fn="onGroupCommand" />
</Listeners>
</ext:CommandColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel ShowHeaderCheckbox="False" runat="server" Mode="Multi"></ext:CheckboxSelectionModel>
</SelectionModel>
<Features>
<ext:Grouping ID="grpMonitor" StartCollapsed="true" runat="server"
GroupHeaderTplString='{columnName}: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'>
</ext:Grouping>
</Features>
</ext:GridPanel>
</Items>
</ext:Panel>
</div>
</form>
</body>
</html>