@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
{
...
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
}).AllowPaging().RowSelecting("rowSelecting").Created("created").RowDataBound("rowDataBound").Render()
<script>
var selIndex = [];
function rowDataBound(args) {
if (args.data['CustomerID'] == 'ANTON') {
selIndex.push(parseInt(args.row.getAttribute('aria-rowindex'))); // push the row index when match data
}
}
function rowSelecting(args) {
if (args.target && args.target.parentElement.classList.contains("e-checkbox-wrapper") && args.data['CustomerID'] != 'ANTON') {
args.cancel = true; //Cancels the default select all rows action
}
}
function created(args) {
document.getElementsByClassName("e-checkselectall")[0].nextSibling.addEventListener('click', function (e) {//Bind the click event to selectAll checkbox
if (!document.getElementsByClassName("e-checkselectall")[0].checked) {
this.selectRows(selIndex); //Select the specific rows in Grid
setTimeout(function () {
document.getElementsByClassName("e-checkselectall")[0].checked = true;
}, 1);
}
else {
this.clearSelection(); //Clear the selection in Grid
setTimeout(function () {
document.getElementsByClassName("e-checkselectall")[0].checked = false;
}, 1);
}
}.bind(this))
}
</script>
|