PDA

View Full Version : Get the number of checked columns for 'checkcolumn' xtype



shashankbs086
17 Apr 2013, 6:32 AM
Hello,

I am not able to get the number of checkboxes checked in a grid which has a column of xtype 'checkcolumn'.
Is it possible to get the count of checkboxes checked in the xtype 'checkcolumn'.



thanks in advance

slemmon
18 Apr 2013, 8:53 PM
There's not a convenience method for getting a count, but there is a checkchanged (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.grid.column.CheckColumn-event-checkchange) event that is raised each time a cell is checked/unchecked. You could listen for the event and keep a tally running that way.

evant
18 Apr 2013, 8:57 PM
Since it's bound to a column, you can also do something like:



var count = 0;
store.each(function(rec){
count += rec.get('foo') ? 1 : 0;
});


Or possibly even (since it should coerce the bools to ints):


var count = store.sum('foo');

mazhar.shaikh
18 Apr 2013, 8:58 PM
var grid = Ext.getCmp('YourGridName');
var selection = grid.getSelectionModel().getSelection();
if (selection.length > 0){
if (selection.length == 1){ /* this line does what you need
/* Do somthing */
}
else{
/* Do somthing */
}
}
}


Thanks

evant
18 Apr 2013, 9:49 PM
It's worth noting that 'checkcolumn' and 'checkboxmodel' are not the same thing here.

shashankbs086
22 Apr 2013, 3:36 AM
Thanks a lot Evant, Your code just worked like a charm :):):)