PDA

View Full Version : [CLOSED] Checkbox Selection Model - loses its checked state on calling direct method



shaileshsakaria
Nov 20, 2013, 3:25 PM
Hi!

I have used checkbox selection model in the grid panel and it is important for me to call direct method on cellediting - edit listener to check some validation.

The problem is when I select the record and perform any edition, direct method works perfectly but selection of the record does not remain in its checked state.

Request you to please look into the below code and suggest the appropriate solution.





<script runat="server">
public class testClass
{
public string TextString1 { get; set; }
public string TextString2 { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
List<testClass> lstTest = new List<testClass>();


for (int i = 1; i < 3; i++)
{
testClass tst = new testClass();

tst.TextString1 = "String" + i;
tst.TextString2 = "";

lstTest.Add(tst);
}

StoreTest.DataSource = lstTest.ToList();
StoreTest.DataBind();

}

[DirectMethod]
public string TestMethod()
{
try
{
return "Direct Method Return";
}
catch (Exception ex)
{
return "NotOk";
}
}
</script>
<script>
var gridEdit = function (editor, e) {

App.StoreTest.getAt(e.rowIdx).data.Text2 = App.StoreTest.data.items[e.rowIdx].data.Text1;
if (App.StoreTest.data.items[e.rowIdx].data.Text1 == "String1") {
App.direct.TestMethod({
success: function (result) {
alert(result);
}
});
}

e.grid.view.refreshNode(e.rowIdx);
}

</script>

<ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
<ext:GridPanel ID="Test" runat="server" IDMode="Static" RowLines="true" ColumnLines="true" Height="500" BodyBorder="1" AutoScroll="true">
<Store>
<ext:Store ID="StoreTest" runat="server" IDMode="Static">
<Model>
<ext:Model ID="TestModel" runat="server" IDMode="Static" IDProperty="Num1" ClientIdProperty="DoNotUse">
<Fields>
<ext:ModelField Name="Text1" Mapping="TextString1"/>
<ext:ModelField Name="Text2" Mapping="TextString2"/>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="colText1" runat="server" DataIndex="Text1" Text="Text1" Sortable="true" Hideable="true">
<Editor>
<ext:TextField ID="txtText1" runat="server" />
</Editor>
</ext:Column>

<ext:Column ID="colText2" runat="server" DataIndex="Text2" Text="Text2" Sortable="true" Hideable="true">
<Editor>
<ext:TextField ID="txtText2" runat="server" />
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing ID="CellEditing2" runat="server">
<Listeners>
<Edit Fn="gridEdit" />
</Listeners>
</ext:CellEditing>
</Plugins>
<SelectionModel>
<ext:CheckboxSelectionModel ID="SampleSelectionModel" runat="server" Mode="Multi" />
</SelectionModel>
</ext:GridPanel>

Baidaly
Nov 20, 2013, 9:45 PM
Hello!

Try to use CheckOnly :


<ext:CheckboxSelectionModel ID="SampleSelectionModel" runat="server" Mode="Multi" CheckOnly="true" />

with the following overriding:


<script>
Ext.override(Ext.grid.plugin.CellEditing, {
showEditor: function (ed, context, value) {
var me = this,
record = context.record,
columnHeader = context.column,
sm = me.grid.getSelectionModel(),
selection = sm.getCurrentPosition(),
otherView = selection && selection.view;

// Selection is for another view.
// This can happen in a lockable grid where there are two grids, each with a separate Editing plugin
if (otherView && otherView !== me.view) {
return me.lockingPartner.showEditor(ed, context, value);
}

me.setEditingContext(context);
me.setActiveEditor(ed);
me.setActiveRecord(record);
me.setActiveColumn(columnHeader);

// Disabled
// Select cell on edit only if it's not the currently selected cell
//if (sm.selectByPosition && (!selection || selection.column !== context.colIdx || selection.row !== context.rowIdx)) {
// sm.selectByPosition({
// row: context.rowIdx,
// column: context.colIdx,
// view: me.view
// });
//}

ed.startEdit(me.getCell(record, columnHeader), value, context);
me.editing = true;
me.scroll = me.view.el.getScroll();
}
});
</script>

Daniil
Nov 21, 2013, 4:44 AM
Hi everybody,

I think the selection is cleared because re-binding of the data happens each request. You should wrap the Page_Load code in !X.IsAjaxRequest condition.

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
List<testClass> lstTest = new List<testClass>();


for (int i = 1; i < 3; i++)
{
testClass tst = new testClass();

tst.TextString1 = "String" + i;
tst.TextString2 = "";

lstTest.Add(tst);
}

StoreTest.DataSource = lstTest.ToList();
}
}