PDA

View Full Version : foreach row in gridpanel



tedl
18 Jan 2010, 4:41 AM
this is code written in C # which is walk through the datagrid.

foreach (DataGridItem dgi in dgPotrdi.Items)
{ string zahtevnica = ((Label)dgi.FindControl("ZAHTEVNICA")).Text;


}


How to walk in the same way after ext: GridPanel by clicking on button

thank you

Condor
18 Jan 2010, 4:52 AM
You mean something like:

grid.getStore().each(function(record){
...
});

daanlib
18 Jan 2010, 4:53 AM
To iterate over a grids rows you should probably try iterating over its store.

edit: Condor beat me ;) see his code example above

tedl
18 Jan 2010, 5:39 AM
You mean something like:

grid.getStore().each(function(record){
...
});


where can I put this?

Condor
18 Jan 2010, 5:44 AM
where can I put this?

What do you mean by 'where'?

You obviously put this code where you want to iterate over the grid rows (assuming the store is loaded).

tedl
18 Jan 2010, 6:02 AM
protected void Button1_Click(object sender, EventArgs e)
{

foreach (DataGridItem dgi in dgPotrdi.Items)
{
string d = ((Label)dgi.FindControl("ZAHTEVNICA")).Text;
}


}
thats the code in C#. How the same code looks like in ExtJS?

daanlib
18 Jan 2010, 6:21 AM
You really shouldn't compare C# to Javascript, there's no direct translation possible. If you want to iterate over your grid rows on clicking a button you should use Condors code in the (click)handler of your button. It should look something like this in your button config:



{
xtype: 'button',
text: 'Click me!',
handler: function() {
grid.getStore().each(function(record) {
var text = record.get("text");
//do stuff with the text
}
}
}

Mike Robinson
18 Jan 2010, 6:49 AM
"When in Rome, do as the Romans do."

The designers devised certain data structures and provided a stable API for using them. Find out what they are, and use them.

Also, don't go "below" the surface API of a particular object. Many of these lists are MixedCollections, and therefore you should reference them using the API of MixedCollection, not its underlying implementation (which should be regarded as "subject to change"). This is what some writers call, "abiding by the social contract."

These practices are the very best way to develop robust and compatible code ... when using any library, in any language. The hair-follicles that you save will be your own.

daanlib
18 Jan 2010, 7:34 AM
"When in Rome, do as the Romans do."

The designers devised certain data structures and provided a stable API for using them. Find out what they are, and use them.

Also, don't go "below" the surface API of a particular object. Many of these lists are MixedCollections, and therefore you should reference them using the API of MixedCollection, not its underlying implementation (which should be regarded as "subject to change"). This is what some writers call, "abiding by the social contract."

These practices are the very best way to develop robust and compatible code ... when using any library, in any language. The hair-follicles that you save will be your own.

I don't understand what you mean by this. Who is going 'below the surface API'? Iterating over a grids rows (to get the data) is best done by iterating over its store, and this is all documented in the API.