1
votes

I am using ng-grid of AngularUI-Grid, and having a checkbox for row selection. It gives me a checkbox in header too.

If user selects checkbox in header, I want some event/method to trigger in $scope, is there any way? I thought by specifying :- checkboxHeaderTemplate , I would get toggleSelectAll() method would get called. but it is not happening. Any clue? Also is there any Event or method of $scope which can get called on multiple row selection or un-selection.

 $scope.gridOptions = {
              data: 'dataList',
              enablePaging: true,
              showFooter: true,
              showFilter: true,
              totalServerItems: 'totalVehicles',
              pagingOptions: $scope.VehpagingOptions,
              filterOptions: $scope.VehfilterOptions.filterText,
              showSelectionCheckbox: true,
              beforeSelectionChange: $scope.beforeVehicleSelectionChange,
              checkboxHeaderTemplate: '<input class="ngSelectionHeader" type="checkbox" ng-show="multiSelect" ng-model="allSelected" ng-change="toggleSelectAll(allSelected, true)"/>'
          };
1

1 Answers

5
votes

I found that ng-grid sends array of item to afterSelectionChange if multiple rows are being selected. I used this instead (this solved my problem):-

 $scope.afterVehicleSelectionChange = function (rowItem, event) {
            if (rowItem.length) {
                _.each(rowItem, function (item) {
                    updateItemOnSelectionChange(item);
                });
            } else {
                updateItemOnSelectionChange(rowItem);
            }
            return true;
        };