user367134
user367134

Reputation: 942

How to loop through the extjs grid object to get its elements and values

I have created a grid and want to access it when I click on save button in a page. How can I loop the grid object to get its elements and its values?

Upvotes: 7

Views: 32686

Answers (4)

user367134
user367134

Reputation: 942

Here is the answer to my question:

for (var i = 0; i < yourGrid.getStore().data.length; i++) { 
    var element = Ext.get(yourGrid.getView().getRow(i));
    var record = yourGrid.getStore().getAt(i);
    alert(record.data.ID);
}

Upvotes: 6

Evan Trimboli
Evan Trimboli

Reputation: 30082

If you want to get a particular field from each record:

var data = [];
store.each(function(rec){
    data.push(rec.get('field'));
});

Upvotes: 20

acteon
acteon

Reputation: 429

In order to get DOM of the row you can use following code :

yourGrid.getNode(yourGrid.getStore().getAt(rowIndex)) 

or you can use getNode directly but incase of any headerbar it may not work as supposed to.

yourGrid.getNode(rowIndex)

This will give you the table row.

Upvotes: 4

Robby Pond
Robby Pond

Reputation: 73484

How do you get the rows from the grid?

var rows = grid.getStore().getRange();

rows will be an Array of Record objects.

Upvotes: 4

Related Questions