Having set up a datastore, how does one loop through, accessing all the elements e.g. given
Code:for(var i=0;i<ds.getTotalCount();i++){ .... }
Having set up a datastore, how does one loop through, accessing all the elements e.g. given
Code:for(var i=0;i<ds.getTotalCount();i++){ .... }
I've done it as follows:
Code:for (var i = 0; i < ds.getCount(); i++) { if (ds.getAt(i).data.isselected) // isselected is a field in my store s += ' ' + ds.data.items[i].id; } Ext.MessageBox.alert('Results', s);
You could use the each method, or getRange(0, count-1). The data property isn't really public , but it's equivalent to the getRange call
Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
Cheers fay and Tim
Using the above example posted by Fay, I get an infinite loop. Since i begins at 0, which is the beginning record address for the datastore and getCount() returns the actual number of records (1 if 1 exists), i will always be less than getCount...or am I missing something here?
Use each method as recommended by Tim. Veeeery easy.
Hi Eric,
I was incrementing i in the for loop (i++), but I now also use the each() method which I never knew existed before! My jaw has repetitive strain injury from thanking TimI really can't get over the amount of time and effort that these guys/gals put into helping us!
Hi !
I have a requirement a little different. I need to create some grids based upon the number of records in the store..
Something like
var mySitePanelStore = new Ext.data.Store({
url: "exampleUrl",
...............................
});
I have a panel like.....
var mySitePanel = new Ext.Panel({ width: '100%',
height: 800,
split: false,
bodyStyle:{"background-color":"white"},
layout: 'absolute',
autoScroll: true
});
What I want to do is something like...
var i =0;
mySitePanelStore.on('load', function(store, records, options)
{
mySitePanelStore.each(function(record) {
//create new panels and add it to an already defined bigger panel
var myIndvSitePnl = new Ext.Panel({ width: 200,
height: 300,
frame: true,
baseCls: 'x-box',
bodyStyle: 'background-color:lightblue',
x: i*200,
y: 25
});
mySitePanel.add(myIndvSitePnl);
};
};
mySitePanel.render(document.body);
This code does not create any of the smaller inner panels though the alert message inside loop suggest that the records on the stored are traversed.
Does anyone has a solution to this? I am using extJs 3.2.1