PDA

View Full Version : [CLOSED] CheckboxSelectionModel "master" select/deselect checkbox is not checked if all rows are selected at store load



ATLAS
Jul 30, 2013, 10:35 AM
Continuing work on my grid, I've hit an issue with CheckboxSelectionModel "master"checkbox selection/deselection. Using the following code as an example, if all rows are in the selected state based on store load initialisation, the "master"checkbox is not checked. I've used your MVC example code to reproduce.

Controller action code :-



public StoreResult GetData()
{
var data = new List<object>();
for (int i = 0; i < 10; i++)
{
data.Add( new { group = "Group 1", test = "Test " + i.ToString(), selected = true });
}

for (int i = 0; i < 8; i++)
{
data.Add(new { group = "Group 2", test = "Test " + i.ToString(), selected = true });
}

var responsive = new StoreResult();
responsive.Total = data.Count;
responsive.Data = data;
return responsive;
}




View code is :-




<script>
var onLoad = function(store, records, successful) {
var grid = App.GridPanel1,
view = grid.getView(),
sm = grid.getSelectionModel(),
recordsToSelect = Ext.Array.filter(records, function (r) { return r.data.selected; });
if (view.viewReady) {
sm.select(recordsToSelect);
} else {
view.on("viewready", function () { sm.select(recordsToSelect); });
}
};


function fnCheckboxSelect(e, record) {

alert("fnCheckboxSelect");
}

function fnCheckboxDeselect(e, record) {
alert("fnCheckboxDeselect");
}


var onGroupCommand = function (column, command, group) {
if (command === 'SelectGroup') {
column.grid.getSelectionModel().select(group.child ren, true);
return;
}
else if (command === 'DeselectGroup') {
column.grid.getSelectionModel().deselect(group.chi ldren, true);
return;
}

Ext.Msg.alert(command, 'Group name: ' + group.name + '<br/>Count - ' + group.children.length);
};


</script>




@(Html.X().GridPanel()
.ID("GridPanel1")
.Height(500)
.Store(Html.X().Store()
.GroupField("group")

.Model(model => model.Add(Html.X().Model()
.Fields(f =>
{
f.Add(Html.X().ModelField().Name("group"));
f.Add(Html.X().ModelField().Name("test"));
f.Add(Html.X().ModelField().Name("selected").Type(ModelFieldType.Boolean));
})))



.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetData"))
.Reader(Html.X().JsonReader().Root("data"))
)
.Listeners(events => events.Load.Fn = "onLoad")
)

.SelectionModel(
Html.X().CheckboxSelectionModel()
.CheckOnly(true)
.Listeners(l =>
{
l.Select.Fn = "fnCheckboxSelect";
l.Deselect.Fn = "fnCheckboxDeselect";
})

)

.ColumnModel(
Html.X().Column()
.Text("Test")
.DataIndex("test"),

Html.X().CheckColumn()
.Text("Selected")
.DataIndex("selected"),

Html.X().CommandColumn()
.Hidden(true)
.GroupCommands(
Html.X().CommandFill(),

Html.X().GridCommand()
.Icon(Icon.TableRowInsert)
.CommandName("SelectGroup"),

Html.X().GridCommand()
.Icon(Icon.TableRowDelete)
.CommandName("DeselectGroup")
)
.Listeners(ls =>
ls.GroupCommand.Fn = "onGroupCommand"
)
)

.Features(
Html.X().Grouping()
.ID("TestGrouping")
.GroupHeaderTplString("{name} ({rows.length} Element{[values.rows.length > 1 ? 's' : '']})")
.HideGroupedHeader(true)
.EnableGroupingMenu(false)
.StartCollapsed(true),

Html.X().RowWrap()
)

)

Daniil
Jul 30, 2013, 1:45 PM
Hi @ATLAS,

Please try this to fix.

.Listeners(events => { events.Load.Fn = "onLoad"; events.Load.Delay = 1; })

ATLAS
Jul 30, 2013, 2:41 PM
Hi @ATLAS,

Please try this to fix.

.Listeners(events => { events.Load.Fn = "onLoad"; events.Load.Delay = 1; })

Sorry Daniil but that doesn't fix it. It maybe significant and point to a timing issue but if I continually reolad the page, I have seen the checkbox checked for a split second before unchecking. Maybe 1 in 15 page loads I see this but very inconsistent.

Daniil
Jul 30, 2013, 3:50 PM
Initially, I tested with FireFox, it worked there. However, it is not enough to get it working in IE or Chrome.

Please try to increase the Delay to 100. It appears to help.

ATLAS
Jul 30, 2013, 5:29 PM
Initially, I tested with FireFox, it worked there. However, it is not enough to get it working in IE or Chrome.

Please try to increase the Delay to 100. It appears to help.

It does. Please close this thread.