7

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?

1

4 Answers 4

20

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

var data = [];
store.each(function(rec){
    data.push(rec.get('field'));
});
Sign up to request clarification or add additional context in comments.

Comments

6

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);
}

1 Comment

That's a poor way to do it. See below.
4

How do you get the rows from the grid?

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

rows will be an Array of Record objects.

2 Comments

can i get example of "Record objects" ?
A record is the data behind a row in the grid.
4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.