-
9 Apr 2012 5:05 AM #1
how set selected row in default when load gridpanel using checkbox selection model?
how set selected row in default when load gridpanel using checkbox selection model?
hi,
i am using extjs 4.0.2a.
in gridpanel using Ext.selection.CheckboxModel.
my json dataGrid Plugins Example_1333975518359.jpgCode:({"totalCount": 5, "dataRows": [{"checked": true, "name": "User1", "date": "13/06/1982"},{"checked": false, "name": "User2", "date": "13/06/1983"},{"checked": true, "name": "User3", "date": "13/06/1984"},{"checked": false, "name": "User4", "date": "13/06/1985"},{"checked": false, "name": "User5", "date": "13/06/1986"}]} )
when gridpanel render check dataIndex checked is true or not. if true mean checkbox is checked otherwise not checked. is it possible to integrate this logic in Ext.selection.CheckboxModel.
i try thisCode:listeners: { afterrender: function() { var current_grid = this; store.on('load', function(){ var data = current_grid.getStore().data.dataRows; var recs = []; Ext.each(data, function(item, index){ if (item.data.checked) { recs.push(index); } }); current_grid.getSelectionModel().selectRows(recs); }) } }
but no luck. any one give suggestion please.
-
9 Apr 2012 5:49 AM #2
Here is some code I used to select checkbox items in a grid:
Regards,Code:this.gridB.getSelectionModel().on('select', function(selModel, model) { // make call to server to get subfields, data is created from gridB subfields list, not from table // table is used to check selected subfields below using ajax call on success Ext.Ajax.request({ method: 'POST', url: 'index.php/mapper/get_tag_subfields/', scope: this, params : { id: this.gridB.getSelectionModel().getSelection()[0].data.id, }, success: function(xhr) { var json = Ext.decode(xhr.responseText); // make sure to decode for loadData to work // data is formatted, just need to load data storeMapperSubfields.loadData(json.data); // mark checkboxes if (json.data.length){ for (var i = 0; i < json.data.length; i++){ var rec = this.gridC.store.getById(json.data[i].id); // json.data[i].getId() if (rec.data.field_type == 's'){ // select all records have have 's' this.gridC.getSelectionModel().select(rec,true,false); } } } }, failure: function() { Ext.getBody().unmask(); alert('AJAX FAILURE: Unable to process call'); } }); }, this);
Scott.


Reply With Quote