Results 1 to 4 of 4

Thread: Checkboxmodel - loop through all rows

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
      0  

    Default Answered: Checkboxmodel - loop through all rows

    I am creating a grid panel that utilizes the checkboxmodel plugin. The grid displays a list of available PDF forms available for download. They are all "checked" by default, but can be unchecked. When a submit button is clicked I would like to show the entire forms list as part of a "summary" and whether each row was selected or not.

    I've seen examples where the selected grid rows using checkboxmodel can be looped-through with getSelectionModel().getSelection(), but how can you loop through all rows in a grid to determine if they are checked or not?

  2. Loop over the store and check if the record is selected:

    Code:
    store.each(function(rec){
        console.log(rec.getId(), selModel.isSelected(rec));
    });

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,237
    Answers
    757
    Vote Rating
    1015
      0  

    Default

    Loop over the store and check if the record is selected:

    Code:
    store.each(function(rec){
        console.log(rec.getId(), selModel.isSelected(rec));
    });
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
      0  

    Default

    Thanks for the quick reply. I think I need to include more info.<br><br>The model/store isn't returning a 'selected' value. I'm just making all forms selected by default using the controller. When the submit button is clicked, the data is sent as json to the server. The following works, but only for selected items. As you can see I'm needing to return the values of each form in the json string.

    var ids = '',
    idTitle = '',
    mygrid = Ext.getCmp('MyGridName')
    Ext.each(mygrid.getSelectionModel().getSelection(), function (row, index, value) {
    if (idTitle != row.data.FormRequired) {
    if (index > 0) {
    ids = ids.slice(0, -1);
    ids = ids + "],";
    }
    ids = ids + '"' + row.data.FormRequired + '":['
    idTitle = row.data.FormRequired;
    }
    ids = ids + '{"Title":"' + row.data.FormName + '","Description":"' + row.data.FormDescription + '","Form Number":"' + row.data.FormNumber + '","Selected":true},';
    })
    ids = ids.slice(0, -1);
    //var selections = [ids];
    //console.log(selections);
    var jsonData = Ext.JSON.encode(form.getValues());
    var jsonWrapped = '{"data":{"QA":' + jsonData + "," + ids + "]}}";
    console.log(jsonWrapped);
    Ext.Ajax.request({
    url: 'webresources/',
    method: 'POST',
    headers: {
    'Content-Type': 'application/json'
    },
    params: jsonWrapped
    });

    I'm pretty new to ExtJs, so please let me know if you need any more info.

  5. #4
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
      0  

    Default Got it

    I got it. Your post lead me in the right direction. i was over thinking how I was using the controller. I gathered all of the data form the store:

    var ids = '',
    idTitle = '';
    this.getBuildResultsStore().each(function (rec) {
    if (idTitle != rec.data.FormRequired) {
    if (index > 0) {
    ids = ids.slice(0, -1);
    ids = ids + "],";
    }
    ids = ids + '"' + rec.data.FormRequired + '":['
    idTitle = rec.data.FormRequired;
    }
    ids = ids + '{"Title":"' + rec.data.FormName + '","Description":"' + rec.data.FormDescription + '","Form Number":"' + rec.data.FormNumber + '","Selected":' + mygrid.selModel.isSelected(rec) + '},';
    })

Tags for this Thread

Posting Permissions

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