Results 1 to 6 of 6

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

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Location
    Bangalore,India
    Posts
    12
    Vote Rating
    0
      0  

    Default 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
    6,154
    Answers
    501
    Vote Rating
    247
      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
    18,383
    Answers
    648
    Vote Rating
    858
      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
    108
    Answers
    6
    Vote Rating
    1
      0  

    Default 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
    18,383
    Answers
    648
    Vote Rating
    858
      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
      0  

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •