PDA

View Full Version : usage of array of objects in a store and grid



louiseburg
7 Dec 2009, 12:34 PM
i have an array of employee objects.

var employeeArray = [];
for( i=1; i<100; i++ ){
var anEmployee = {};
anEmployee.name = 'nm'+i;
anEmployee.surname = 'snm'+i;
anEmployee.no = i;
employeeArray.push(anEmployee);
}

here, i want to show these employee objects in a grid?
what kind of store should i use? how could that array be bounded to the grid?
dou you have a sample code or pseudo code ?

MiamiCoder
7 Dec 2009, 3:08 PM
ArrayStore. Here you go:



var employeeRecord = Ext.data.Record.create([
{name:'name',mapping:'name'},
{name:'surname',mapping:'surname'},
{name:'no',mapping:'no'},
]);

var employeeArray = [];

for( i=1; i<100; i++ ){
var anEmployee = {};
anEmployee.name = 'nm'+i;
anEmployee.surname = 'snm'+i;
anEmployee.no = i;
employeeArray.push(anEmployee);
}

var g = new Ext.grid.GridPanel({
id:'inProgressGrid',
title:'Employees',
width:600,
height:600,
renderTo:Ext.getBody(),
columns:[{header:'Name',id:name}],
autoExpandColumn:name,
store:new Ext.data.ArrayStore({
idIndex: 2,
fields:employeeRecord,
data:employeeArray
}),
viewConfig:{
forceFit:true,
emptyText:'No employees to display'
}
});