How to programmatically deselect the 'select all' checkbox?
Hi-
Another question, how do we clear the 'select all' checkbox? I've got a button off-grid that process the selected rows and can clear the selection a variety of ways (setting the selected item array to zero length or calling
$scope.gridOptions.$gridScope.toggleSelectAll(false);
but I can't seem to clear the 'select all' box. I've tried
$scope.gridOptions.$gridScope.allSelected = false;
// or
$scope.gridOptions.allSelected = false;
but neither seem to affect the checkbox.
thanks!
it looks like its because allSelected is on a child scope because of the way ng-model handles it weird....can you clear it with jQuery?
Probably, I haven't tried that as I hoped it could work in the angular world, but I will give it a shot. It's causing some (minor) user anguish here so by hook or crook I'd like to fix it :-)
$scope.$watch('selectedResources', function(){
if($scope.selectedResources.length == 0) {
$scope.gridOptionsBig.$gridScope.toggleSelectAll(null, false);
var selectAllHeader = angular.element(".ngSelectionHeader").scope();
if(selectAllHeader) selectAllHeader.allSelected = false;
}
}, true);
where selectedResources is bound to $scope.gridOptionsBig.selectedItems.
the solution above, based on $watch, doesn't work for me in version 2.0.10
Hi,
I found that $scope.allSelected works, it doesn't trigger the on-change event however I used
$scope.$on('ngGridEventData', function(){
$scope.gridOptions.selectAll(true);
$scope.allSelected = true;
});
note: ngGridEventData is triggered each time there is a record entered to the data array, I used this for selecting all when the data becomes available, the reason I have this is I want all rows selected when the grid first displays. The problem with just doing selectAll without the $on ngGridEventData is that the data isn't in the grid and the grid hasn't got all its functionality yet. In the OP's case a button onclick shouldn't present a problem because the data should be in the grid by the time the user gets to click it. Sorry for the long winded reply, first time to answer a question.
I think this should be good for you mxreppy
$scope.processSelectedRows = function() {
// process rows
// deselect all rows
$scope.gridOptions.selectAll(false);
$scope.allSelected = false;
};
Hope this helps Regards Jon
$scope.allSelected and $scope.gridOptions.allSelected are both undefined for me. Doing $scope.gridOptions.selectAll(false) does not deselect the header check box.
Has this question bean resolved? I simply avoid it by replacing the 'allSelected' with an object and adding watch to selectedItems
workaround : $("input.ngSelectionHeader:checkbox").prop('checked', false);
work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }
work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }
work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }
work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }
I've found that both dimitrivalex and Hals9000 workarounds don't really work for me. They both uncheck the header's checkbox, but they also make it so that if you select the header's checkbox again it doesn't select all rows in the grid like it should (you would have to deselect it again before it worked). I've gotten Hals9000's workaround to fully work if i have the click event trigger 3 times, but it seems like that shouldn't be necessary.
Has anyone found a good solution to this?
Hi there,
I've just found a solution.
Just replace allSelected with $parent.allSelected (or any name you want) in your custom checkbox header template:
checkboxHeaderTemplate: '<input class="ngSelectionHeader" type="checkbox" ng-model="$parent.allSelected" ng-change="toggleSelectAll($parent.allSelected)"/>'
Then use:
$scope.gridOptions.$gridScope['allSelected'] = false;
@dezz727 : Any idea on how it can be done,if I don't use a checkboxHeaderTemplate?
This is the solution I use to deselect selection's check all:
$scope.gridApi.grid.selection.selectAll = false;
This also assumes that you used onRegisterApi to register the api when you created the grid
$scope.gridOptions.onRegisterApi = function (gridApi) {
$scope.gridApi = gridApi;
}
Note that this method will only unselect the select all checkbox. If you want to deselect everything else, you'll have to use the api to deselect those as well:
$scope.gridApi.selection.clearSelectedRows()
Would really appreciate if anyone can send controller code. Don't really know where to put toggleSelectALL function. I have tried different things but none is working. Apologies for my noviceness. Many thanks.
dimitrivalax workaround solved my issue.
the other solutions, produced error of undefined.
workaround:
$("input.ngSelectionHeader:checkbox").prop('checked', false);