BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
<div id="Grid" ng-init="chkinit()" ej-grid e-datasource="data" e-columns="columns" e-recordclick="recordClick" e-allowselection="true" e-selectiontype="multiple" e-actioncomplete="actioncomplete" e-allowsorting="allowsorting" e-templaterefresh="refreshTemplate" e-databound="dataBound" e-actionbegin="actionbegin" e-allowpaging="allowpaging" e-pagesettings="pagesettings"></div> $scope.dataBound = function (args) { $("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange }); $("#headchk").ejCheckBox({ "change": headCheckChange }); this.model.indexes = {}; } $scope.refreshTemplate = function (args) { $("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange }); $("#headchk").ejCheckBox({ "change": headCheckChange, checked: false }); |
$scope.dataBound = function (args) { $("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange }); $("#headchk").ejCheckBox({ "change": headCheckChange }); this.model.indexes = {}; /* Additional property*/ } $scope.actionbegin = function (args) { //Stores the selected index on paging starts. if (args.requestType == "paging") { if (this.selectedRowsIndexes.length > 0) this.model.indexes[args.previousPage] = this.selectedRowsIndexes; } }
$scope.actioncomplete = function (args) { //Retriev and select the rows on paging ends if (args.requestType == "paging") { var indx = this.model.indexes[args.currentPage]; for (var i = 0; i < (indx || []).length; i++) { $("#Grid .rowCheckbox").eq(indx[i]).ejCheckBox("model.checked", true) this.selectRows(indx[i]); } } |
var newColumns = [ . . . . . { headerText: "", commands: [ { type: "", buttonOptions: { htmlAttributes: { id: "CustomButton", class: "btn-white btn-sm editClick", style: " width: 60px;" }, text: "Edit", click: "editClick" } } ],
isUnbound: true, textAlign: ej.TextAlign.Center, width: 70 } |
<div id="Grid" ng-init="chkinit()" ej-grid e-datasource="data" e-columns="columns" e-recordclick="recordClick" . . . .> $scope.recordClick = function (args) { $("#Grid .editClick").ejButton({ "click": $scope.editClick });
. . . . |
$scope.editClick = function (args) { var grid = $("#Grid").ejGrid("instance"); var index = this.element.closest("tr").index(); var record = grid.getCurrentViewData()[index]; alert(JSON.stringify(record)) }
var newColumns = [ . . . . { headerText: "", commands: [ { type: "", buttonOptions: { htmlAttributes: { id: "CustomButton", class: "btn-white btn-sm editClick", style: " width: 60px;" }, text: "Edit", click: $scope.editClick } } ],
isUnbound: true, textAlign: ej.TextAlign.Center, width: 70 } ];
. . . . $scope.recordClick = function (args) { //No need for this line $("#Grid .editClick").ejButton({ "click": $scope.editClick });
. . . . |
function headCheckChange(e) { $("#Grid .rowCheckbox").ejCheckBox({ "change": checkChange }); gridObj = $("#Grid").data("ejGrid"); var pager = gridObj.model.pageSettings; if ($("#headchk").is(':checked')) { $(".rowCheckbox").ejCheckBox({ "checked": true }); gridObj.multiSelectCtrlRequest = true; gridObj.selectRows(0, pager.pageSize); // To Select all rows in Grid Content
//To maintain the selected indexes for all pages for (var i = 1, j; i <= pager.totalPages; i++) { var ind = gridObj.model.indexes[i] = []; j = i == pager.totalPages ? pager.totalRecordsCount % pager.pageSize : pager.pageSize; while (--j != -1) { ind.push(j); } } } else { $(".rowCheckbox").ejCheckBox({ "checked": false }); gridObj.model.indexes = {}; gridObj.clearSelection(); // To remove selection for all rows } }
function checkChange(e) { gridObj = $("#Grid").data("ejGrid"); var rowCheck = $(".rowCheckbox:checked"), cp = gridObj.model.pageSettings.currentPage; gridObj.model.indexes[cp] = gridObj.model.indexes[cp] || []; var ind = gridObj.model.indexes[cp], row = this.element.closest("tr").index(); if (this.model.checked) ind.push(row); else ind.splice(ind.indexOf(row), 1);
var total = gridObj.model.pageSettings.totalRecordsCount, chks = 0; for (var p in gridObj.model.indexes) { chks += gridObj.model.indexes[p].length } if (total == chks) /*check whether all checkboxes are clicked*/ $("#headchk").ejCheckBox({ "checked": true }); else $("#headchk").ejCheckBox({ "checked": false });
if (($("#headchk").is(':checked')) && this.model.checked != true) { for (i = 0; i < rowCheck.length; i++) { gridObj.multiSelectCtrlRequest = true; gridObj.selectRows($(rowCheck[i]).parents("tr").index());// To prevent unselection of other rows when a checkbox is unchecked after selectAll rows } } if (this.model.checked == false) { $("#headchk").ejCheckBox({ "checked": false }); } gridObj.multiSelectCtrlRequest = true;//For MultiSelection using Checkbox $scope.actioncomplete = function (args) { //Retriev and select the rows on paging ends if (args.requestType == "paging") { var hc = $("#headchk").ejCheckBox("model.checked"); //Checked for header checkbox var indx = this.model.indexes[args.currentPage]; for (var i = 0; i < (hc ? this.model.currentViewData : (indx || [])).length; i++) { $("#Grid .rowCheckbox").eq(hc ? i : indx[i]).ejCheckBox("model.checked", true) this.selectRows(hc ? i : indx[i]); } } |