Reputation: 36126
I'm very new to EXTJS, so I dont fully understand how does it work yet, but I manage to build a grid that is a result of a select (so it is not mapped directly to a table). One of the columns of this grid is ID. I also added a checkbox to the grid
this.columns =
[
{
header: 'Selected',
dataIndex: 'Selected',
xtype: 'checkcolumn'
},
....rest of the columns
and on my model I have:
fields:
[
{ name: 'Selected', type: 'bool' },
{ name: 'ID', type: 'int' },
...rest of the fields
what I need is, on the click of a button (which is already added), to get a list of the IDs that had the Selected property set to true.
Any Idea how I can do that?
Upvotes: 1
Views: 201
Reputation: 23975
Well that is simple (if I understand you right), a grid has a selection model which handles these selection. You will just need to get the selection model and get all selected records.
There are also itemclick,selectionchange events that fires for each selection. Where the second gives a array of selected records.
And I guess the Ext.selection.CheckboxModel can be also interest you.
Edit:
OK I guess all above is not what you want but maybe quite interesting. What you need is to iterate over all records of the store which can be done with store.each(). Do this in the scope of your button and will a array. Example
var myGrid = Ext.getCmp('MyGrid');
var list = [];
myGrid.store.each(function(rec) {
if(rec.data.Selected)
list.push(rec);
return true;
});
To get the currently selected record(model) do this:
var myGrid = Ext.getCmp('MyGrid'),
sm = myGrid.getSelectionModel(),
selection = sm.getSelection(), // gives you a array of records(models)
len = selection.length,
i = 0,
idList = [];
for (; i<len; i++) {
idList.push(selection[i].data.ID);
}
Upvotes: 3