PDA

View Full Version : Checkboxmodel - loop through all rows



rocherrr
4 Mar 2013, 12:55 PM
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?

evant
4 Mar 2013, 1:11 PM
Loop over the store and check if the record is selected:



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

rocherrr
4 Mar 2013, 1:56 PM
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.

rocherrr
4 Mar 2013, 2:25 PM
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) + '},';
})