1. #1
    Sencha User
    Join Date
    Oct 2012
    Location
    Bangalore,India
    Posts
    12
    Vote Rating
    0
    shashankbs086 is on a distinguished road

      0  

    Default Answered: Get the number of checked columns for 'checkcolumn' xtype

    Answered: Get the number of checked columns for 'checkcolumn' xtype


    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

  2. Since it's bound to a column, you can also do something like:

    Code:
    var count = 0;
    store.each(function(rec){
        count += rec.get('foo') ? 1 : 0;
    });
    Or possibly even (since it should coerce the bools to ints):
    Code:
    var count = store.sum('foo');

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,021
    Answers
    385
    Vote Rating
    183
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    There's not a convenience method for getting a count, but there is a checkchanged event that is raised each time a cell is checked/unchecked. You could listen for the event and keep a tally running that way.

  4. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,915
    Answers
    458
    Vote Rating
    630
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      1  

    Default


    Since it's bound to a column, you can also do something like:

    Code:
    var count = 0;
    store.each(function(rec){
        count += rec.get('foo') ? 1 : 0;
    });
    Or possibly even (since it should coerce the bools to ints):
    Code:
    var count = store.sum('foo');
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #4
    Sencha User
    Join Date
    Feb 2013
    Location
    NZ
    Posts
    67
    Answers
    5
    Vote Rating
    0
    mazhar.shaikh is on a distinguished road

      0  

    Default grid.getSelectionModel().getSelection();

    grid.getSelectionModel().getSelection();


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

  6. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,915
    Answers
    458
    Vote Rating
    630
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    It's worth noting that 'checkcolumn' and 'checkboxmodel' are not the same thing here.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  7. #6
    Sencha User
    Join Date
    Oct 2012
    Location
    Bangalore,India
    Posts
    12
    Vote Rating
    0
    shashankbs086 is on a distinguished road

      0  

    Default


    Thanks a lot Evant, Your code just worked like a charm