admin管理员组

文章数量:1355542

When running a getSelectionModel().clearSelections() on a grid that uses a Ext.selection.CheckboxModel and all rows was selected using the "select all" check box at the top of the select column, the "select all" check box remains checked.

I did a dirty hack to get around this but I wish to know if there is a cleaner way or if this is a bug.

When running a getSelectionModel().clearSelections() on a grid that uses a Ext.selection.CheckboxModel and all rows was selected using the "select all" check box at the top of the select column, the "select all" check box remains checked.

I did a dirty hack to get around this but I wish to know if there is a cleaner way or if this is a bug.

Share Improve this question edited May 6, 2013 at 14:52 Tiago Sippert 1,3307 gold badges24 silver badges33 bronze badges asked Oct 23, 2012 at 14:39 Tommy StrandTommy Strand 1,4042 gold badges15 silver badges15 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

I'd try to put a listener on a grid ponent to track selection changes (not sure if it will help):

listeners: {
   selectionchange: function(grid, selected) {
        if(!selected.length) {
            grid.getSelectionModel().deselectAll();
        }
   }
}

Btw, have you tried to do getSelectionModel().deselectAll()? clearSelections is deprecated in ExtJS 4.1 and it's runned on view not selection model.

EDIT: After reading Vyacheslav Voronchuk's answer I did back and verified that the documentation does indeed say that clearSelection is a private function that does not send an event, thereby not notifying that the checkbox should be cleared.

.getSelectionModel().deselectAll()

is indeed the way to go.

For historical reasons I include my original dirty hack that I did to get around the problem:

var el = Ext.get("gridcolumn-1031");
el.removeCls('x-grid-hd-checker-on');

gridcolumn-1031 is the id of the div wrapping the checkbox in my app. It is randomly generated so you need to dom inspect your own to do the same dirty hack.

Disclamer! Use at your own peril.

I do not condone dirty hacks like this since it is not likely to survive auto generated id change of my grid, but it will get the app approved by my client while we wait for a more permanent solution.

For removing grid header selection:

.getSelectionModel().deselectAll()

didn't work for me because my grid is already empty.

This works though (from above hack):

var selectionHeadID = Ext.getCmp('ingameGrid').headerCt.getHeaderAtIndex(0).getId();
var el = Ext.get(selectionHeadID);
el.removeCls('x-grid-hd-checker-on');

Hope this helps!

本文标签: javascriptHow to uncheck the select all checkbox in ExtselectionCheckboxModelStack Overflow