I'm using AngularJS ng-grid, where assigning the $scope.gridOptions associated onRegisterApi with function as listed in my code below:
onRegisterApi: function (gridApi) {
alert("in");
$scope.gridApi = gridApi;
gridApi.selection.on.rowSelectionChanged($scope, function (row) {
alert("in");
var msg = 'row selected ' + row.isSelected;
$log.log(msg);
console.log(msg);
//$window.alert(msg);
});
gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows) {
alert("in");
var msg = 'rows changed ' + rows.length;
$log.log(msg);
// $window.alert(msg);
console.log(msg);
});
//Added for custom paging
gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
paginationOptions.pageNumber = newPage;
paginationOptions.pageSize = pageSize;
$scope.pageSize = pageSize;
$scope.currentPage = newPage;
$scope.totalPage = Math.ceil($scope.gridOptions.totalItems / $scope.pageSize);
$scope.loadData();
});
//custom sort
$scope.gridApi.core.on.sortChanged($scope, function (grid, sortColumns) {
if (sortColumns.length == 0) {
sortingOptions = null;
} else {
sortingOptions = sortColumns[0].sort.direction;
}
$scope.loadData();
});
}
However, when trigerring gridApi.selection.on.rowSelectionChanged/gridApi.pagination.on.paginationChanged/$scope.gridApi.core.on.sortChanged via clicking on row, changing one of the pagination options such as the pagesize and clicking on sort icon as listed in image ng-grid.PNG, the above mentioned methods are not being called, please advise.
Note: I set the useExternalPagination/useExternalSorting/useExternalFiltering to "true" and enabled the "enableRowSelection: true".
Please advise!!!!
Issue is with the mixture of both ng-grid and ui-grid. Try using any one framework , i suggest ui-grid compare to ng-grid.
since in the HTML , ng-grid used , onRegisterApi is not getting triggered as it is related to ui-grid.
So using ui-grid is fixed onRegisterApi call issue.
and angular version included is not compatible, so i have changed the imports and few ui-grid options of pagination and selection.
Here is the updated demo - http://plnkr.co/edit/1oUIj7IprYoCpYJ6u5OF?p=preview
Please check this docs - http://ui-grid.info/docs/#!/api/ui.grid.pagination.directive:uiGridPagination.
Hope this helps.