PDA

View Full Version : passing array of elements to Grid



11 Oct 2011, 2:36 AM
Team,

I have two grids , in which one of the grid contains data loaded from db.

On Cell click, I want to get the selected values of first grid and query them and display the result in second grid.

I was successful in getting records into this array. How to pass this array to secondgridStore which was already loaded.

var reqarr= new Array();
reqarr=finalreq.split(',');
alert(reqarr);

var secondgriddata= {
records:[
for(i=0; i<reqarr.length;i++)
{name:reqarr[i]}
]
};

secondgridStore.loadData(secondgriddata);

It is showing error in Console(Syntax error in for loop).

when I try like this
var secondgriddata= {
records:[

{name:reqarr[0]},
{name:reqarr[1]}
]
};

this results in success, but keeping static values is not good at all times right!!

How to pass this array to Data records?

Please help me out at earliest....

twaindev
11 Oct 2011, 5:19 AM
Perhaps this sample helps:


Ext.onReady(function() {
var panel = Ext.create('Ext.grid.Panel', {
title: 'Test loadData',
renderTo: Ext.getBody(),
columns: [{
text: 'Name',
dataIndex: 'name',
flex: 1
}]
}),
array = 'Record A,Record B,Record C,Record D,Record E'.split(','),
records = [],
i = 0, ln = array.length;

for(; i < ln; i+=1) {
records.push({ name: array[i]});
}

panel.getStore().loadData(records);
});