PDA

View Full Version : iterating thru records



bagus
1 May 2007, 8:56 PM
I'm trying to edit the 'edit-grid' example to have it write out the data in the supplied Plants.xml file.

I want to do this because ultimately I want to send this data back to the server so it can be saved to a database. But that's another question for later.

For now, I'm wondering how to get started.

So by the time the edit-grid.js reaches the ds.load(); can I write something like this:
(probably not since i tried it)
....
ds.load();
var firstPlant = ds.getAt('0');
var firstPlantCommon = firstPlant.get('common');
alert("Congratulations! " + firstPlantCommon);

Anyways, how can I print out the common name for the first plant in the xml file?

Here's the example:
http://www.extjs.com/deploy/ext/examples/grid/edit-grid.html

Thanks for the help. I know I'll have fun getting listeners set up for updated records and getting the data sent back to the server, but I'd be at least on my way if I could get this straight.

Bagus

Animal
1 May 2007, 11:09 PM
That code looks good apart from getAt() takes a number. I know the docs say string, but it's a copy/paste mistake. I've just fixed it in SVN.

Just a hint: You can experiment with all these objects on the Firebug command line. Just type in javascript which returns an object, and that object will be displayed, and clickable to introspect. So you can type in all those lines and see exactly what they produce.

bagus
4 May 2007, 10:03 AM
So fwiw, here's a solution to iterating thru the plant data.


ds.on("load", doPlants);
function doPlants() {
ds.each(doRecord);
}

function doRecord() {
var colCount=cm.getColumnCount();
var colName=cm.getDataIndex(0);
var plantInfo="";
for (var colCounter=0; colCounter < colCount; w++) {
var colName=cm.getDataIndex(colCounter);
plantInfo += colName + " : " + this.get(colName) + ", ";
}
console.log(plantInfo);
}


Thoughts? Thanks