Is there an example out there in javascript and/or jquery where someone has a 'Check all' checkbox that checks all checkboxes across all pages of a grid?
I have been trying for 3 days now and I am not finding a clean answer.
What i have now is ugly and does not really work...
function onRequestEnd(e) {
var masterCbChecked = $("#masterCheckBox").is(':checked');
var grid = $("#grid").data("kendoGrid");
for (var i = 0; i < grid.dataSource.total(); i ++) {
var dataRow = $("#grid").data("kendoGrid").dataSource.data()[i];
var elementRow = grid.table.find(".cbAdvisor")[i];
if (elementRow != null) {
var checked = elementRow.checked,
row = $(elementRow).closest("tr"),
dataItem = grid.dataItem(grid.tbody.find("tr").eq(i));
checkedIds[dataItem.DimAgentId] = masterCbChecked;
if (masterCbChecked) {
//-select the row
elementRow.checked = true;
row.addClass("k-state-selected");
dataRow.IsSelected = true;
} else {
//-remove selection
elementRow.checked = false;
row.removeClass("k-state-selected");
dataRow.IsSelected = false;
}
}
}
}
function checkAll(ele) {
var state = $(ele).is(':checked');
var grid = $("#grid").data("kendoGrid");
//grid.dataSource.pageSize(grid.dataSource.total());
//grid.dataSource.read();
//grid.refresh();
var currentPage = $("#grid").data("kendoGrid").dataSource.page();
checkedIds = {};
//for (var a = 0; a < modelJson.length; a ++) {
// var m = modelJson[a];
// m.IsSelected = true;
//}
for (var a = 1; a < 2; a ++) {
var pager = grid.pager;
pager.bind('change', a);
grid.one("dataBound", function () {
this.dataSource.page(a);
});
grid.dataSource.fetch();
for (var i = 0; i < grid.dataSource.total(); i ++) {
var dataRow = $("#grid").data("kendoGrid").dataSource.data()[i];
var elementRow = grid.table.find(".cbAdvisor")[i];
if (elementRow != null) {
var checked = elementRow.checked,
row = $(elementRow).closest("tr"),
dataItem = grid.dataItem(grid.tbody.find("tr").eq(i));
checkedIds[dataItem.DimAgentId] = state;
if (state) {
//-select the row
elementRow.checked = true;
row.addClass("k-state-selected");
dataRow.IsSelected = true;
} else {
//-remove selection
elementRow.checked = false;
row.removeClass("k-state-selected");
dataRow.IsSelected = false;
}
}
}
pager.bind('change', currentPage);
grid.one("dataBound", function () {
this.dataSource.page(currentPage);
});
grid.dataSource.fetch();
//mark for paging
if (dataRow != null) {
if (state) {
dataRow.IsSelected = true;
} else {
dataRow.IsSelected = false;
}
}
};
if (!state) {
checkedIds = {};
}
//grid.dataSource.pageSize(50);
//grid.refresh();
}
Aucun commentaire:
Enregistrer un commentaire