ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

How to programmatically deselect the 'select all' checkbox?

Open mxreppy opened this issue 13 years ago • 18 comments

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!

mxreppy avatar May 14 '13 01:05 mxreppy

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?

orneryd avatar Jun 04 '13 04:06 orneryd

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 :-)

mxreppy avatar Jun 04 '13 14:06 mxreppy

        $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.

arindambiswas avatar Aug 28 '13 08:08 arindambiswas

the solution above, based on $watch, doesn't work for me in version 2.0.10

julienboulay avatar Apr 30 '14 15:04 julienboulay

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

JonLally avatar May 06 '14 13:05 JonLally

$scope.allSelected and $scope.gridOptions.allSelected are both undefined for me. Doing $scope.gridOptions.selectAll(false) does not deselect the header check box.

dparizek avatar Jul 14 '14 18:07 dparizek

Has this question bean resolved? I simply avoid it by replacing the 'allSelected' with an object and adding watch to selectedItems

newnewnewhuman avatar Aug 01 '14 07:08 newnewnewhuman

workaround : $("input.ngSelectionHeader:checkbox").prop('checked', false);

dimitrivalax avatar Nov 06 '14 13:11 dimitrivalax

work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }

Hals9000 avatar Nov 11 '14 05:11 Hals9000

work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }

Hals9000 avatar Nov 11 '14 05:11 Hals9000

work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }

Hals9000 avatar Nov 11 '14 05:11 Hals9000

work around: var allChecked = $("input.ngSelectionHeader:checkbox").prop('checked'); if (allChecked) { $("input.ngSelectionHeader:checkbox").click(); } else { $scope.gridOptions.selectAll(false); }

Hals9000 avatar Nov 11 '14 05:11 Hals9000

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?

endorphins avatar Jan 29 '15 17:01 endorphins

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 avatar Feb 18 '15 21:02 dezz727

@dezz727 : Any idea on how it can be done,if I don't use a checkboxHeaderTemplate?

kmittal avatar May 06 '15 15:05 kmittal

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()

ulandgrant avatar Oct 29 '15 15:10 ulandgrant

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.

imadulhaque avatar May 12 '16 13:05 imadulhaque

dimitrivalax workaround solved my issue.

the other solutions, produced error of undefined. workaround: $("input.ngSelectionHeader:checkbox").prop('checked', false);

SyedZeenath avatar Jun 04 '19 06:06 SyedZeenath