<script type="text/x-jsrender" id="checkboxTemplate">
<input type="checkbox" class="rowCheckbox" />
</script>
<script type="text/x-jsrender" id="headerTemplate">
<input type="checkbox" id="headchk" />
</script>
|
function create(args) {
$("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange });
$("#headchk").ejCheckBox({ "change": headCheckChange });
}
function complete(args) {
$("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange });
$("#headchk").ejCheckBox({ "change": headCheckChange, checked: false });
} |
<script type="text/javascript">
$(function () {// Document is ready.
var records;
var dataManager = ej.DataManager({
url: "/Grid/DataSource",
adaptor: new ej.UrlAdaptor()
});
$("#Grid").ejGrid({
dataSource: dataManager,
allowSelection: true,
selectionType: "multiple",
allowPaging: true,
allowFiltering: true,
filterSettings: { filterType: "excel" },
columns: [
{ type: "boolean", width: 100, headerTemplateID: "#headerTemplate", template: true, templateID: "#checkboxTemplate", textAlign: ej.TextAlign.Center },//The checkbox column is bound to the grid using template property and headerTemplateID property
{ field: "OrderID", headerText: "Order ID", isPrimaryKey: true, width: 100 },
{ field: "CustomerID", headerText: "Customer ID", width: 130 },
{ field: "Freight", headerText: "Freight", width: 100, format: "{0:C}" },
{ field: "ShipCountry", headerText: "ShipCountry", width: 100 }
],
dataBound: "create",
actionComplete: "complete",
recordClick: "recordClick",
actionBegin: "ab",
rowSelected: "rowselected",
});
});
function checkChange(e) {
gridObj = $("#Grid").data("ejGrid");
var rowCheck = $(".rowCheckbox:checked");
----------------------------------------------
}
function headCheckChange(e) {
var grid = $("#Grid").ejGrid("instance");
$("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange });
gridObj = $("#Grid").data("ejGrid");
if ($("#headchk").is(':checked')) {
records = grid.selectedRowsIndexes;
$(".rowCheckbox").ejCheckBox({ "checked": true });
gridObj.multiSelectCtrlRequest = true;
gridObj.selectRows(0, gridObj.model.pageSettings.pageSize); // To Select all rows in Grid Content
}
else {
$(".rowCheckbox").ejCheckBox({ "checked": false });
gridObj.clearSelection(); // To remove selection for all rows
var grid = $("#Grid").ejGrid("instance");
for (var i = 0 ; i < records.length ; i++) {
grid.getRowByIndex(records[i]).find(".rowCheckbox").ejCheckBox({ "checked": true });
grid.selectRows(records[i]);
}
}
}
</script> |