Results 1 to 2 of 2

Thread: usage of array of objects in a store and grid

  1. #1

    Default usage of array of objects in a store and grid

    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 ?

  2. #2
    Sencha User MiamiCoder's Avatar
    Join Date
    Mar 2009
    Location
    Miami, FL
    Posts
    144

    Default

    ArrayStore. Here you go:

    Code:
    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'
    }
    });

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •