PDA

View Full Version : [2.0]GridPanel - CheckBoxSelectionModel



tinker
7 Mar 2008, 4:47 AM
Hi,

When using the CheckboxSelectionModel for GridPanel you get a very nice feature - check/uncheck the checkbox in the header to propagate the choice through all the rows. However what i wanted to know is this:

Scenario 1:
Check the header checkbox. All rows get selected. Now uncheck (unselect) on of the rows. The header checkbox is still in "checked" state.

Scenario 2:
Start selecting all rows one by on (not checking the header checkbox). When all rows are selected, the header checkbox is still in "unchecked" state.

Has anyone found a solution to this? I have some thoughts about getting over this but just wanted to check if anyone has a solution before re-inventing the wheel.

Thankx

tinker
7 Mar 2008, 8:40 PM
Well... found a fix by myself. Use the following code:



var cm = new Ext.grid.CheckboxSelectionModel();
cm.on
(
{
'selectionchange': function(s)
{
var hdrEl = Ext.get(this.grid.el.query('div.x-grid3-hd-checker'));
var totalRows = this.grid.view.getRows().length;

if (this.getCount() < totalRows)
hdrEl.removeClass('x-grid3-hd-checker-on');
else
hdrEl.addClass('x-grid3-hd-checker-on');
}
}
);


and then use the object "cm" in the grid's "colModel".