|
@Html.EJS().Grid("grid").DataSource((IEnumerable<object>)ViewBag.dataSource).AllowPaging().Height("348px").Columns(col
=>
{
col.Type("checkbox").Width("50").HeaderTemplate("#headerTemplate").Add();
}).HeaderCellInfo(“headerCellInfo”).ActionBegin(“actionBegin”).ActionComplete(“actionComplete”).SelectionSettings(select
=> select.Type(Syncfusion.EJ2.Grids.SelectionType.Multiple)).Render()
<script
id="headerTemplate" type="text/x-template">
<input
id="chk" />
</script>
function headerCellInfo(args) {
if (args.cell.column.type == 'checkbox') {
var input = args.node.querySelector('#chk');
let chkBox = new ej.buttons.CheckBox({
change: changeHandler,
});
chkBox.appendTo(input);
}
}
// select/unselect current page records
function changeHandler(args) {
var length = grid.currentViewData.length;
if (args.checked) {
grid.selectRowsByRange(0, length - 1);
} else {
grid.selectRows([]);
}
}
function actionBegin(args) {
if (args.requestType == 'paging') {
grid.selectionModule.isInteracted = false;
}
}
//
reset the checkbox based on the selectino
function actionComplete(args) {
if (args.requestType == 'paging') {
grid.element.querySelector('#chk').ej2_instances[0].checked =
args.rows.filter((row) => row.isSelected).length ==
grid.currentViewData.length;
}
}
|