Aminesrine
Aminesrine

Reputation: 2140

Extjs4 save all grid data in a table

I know how to get a value from a selected row of a grid, just like this:

var records = Ext.getCmp('My_Grid').getSelectionModel().getSelection();
var record  = records.length === 1 ? records[0] : null;
alert(record.get('name'));

But what I want is to get the name of all rows of the grid. To do it, I have used the method above, to write this functional function:

var MonTableau = new Array();
for (var j=0; j<=Ext.getCmp('My_Grid').getStore().getCount()-1; j++) {
Ext.getCmp('My_Grid').getView().select(j);
var records = Ext.getCmp('My_Grid').getSelectionModel().getSelection();
var record  = records.length === 1 ? records[0] : null;
MonTableau[j+1]=record.get('name');
                }

But it's not professional, I want more simple and professional method.

Upvotes: 1

Views: 2612

Answers (1)

Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15310

The ExtJS store provides an each function which applies a passed fn for each record cached (already loaded) in the store:

var myStore = Ext.getCmp('My_Grid').getStore();
myStore.each(function(rec) {
    console.log(rec.get('name'));
});

P.S. I'm using console.log(); rather than alert(); as I think it's easier to read everything from the browser log.

Upvotes: 1

Related Questions