PDA

View Full Version : DataReader, Store, DataRecord, Grid



ieroglif
4 Apr 2008, 7:17 AM
php generate json like:


{"write":true,
"update":true,
"delete":true,
"grid_data":[
{"gr_id":"1","gr_name":"Name1","gr_code":"CODE2","gr_note":"asd"},
{"gr_id":"2","gr_name":"Name2","gr_code":"CODE2","gr_note":"asd"},
{"gr_id":"3","gr_name":"Name3","gr_code":"Code3","gr_note":"Note3"}
]}


javascript:


var myRecord = Ext.data.Record.create([
{name: 'id', mapping: 'gr_id' },
{name: 'name', mapping: 'gr_name' },
{name: 'code', mapping: 'gr_code' },
{name: 'note', mapping: 'gr_note' }
]);

var myGridStore = new Ext.data.Store({
reader: new Ext.data.DataReader({
recordType: BrancheRecord
}),
url: myurl
})
var myGrid = new Ext.grid.GridPanel({
store: myGridStore,
columns: [
{
header: "id",
width: 30,
sortable: true,
dataIndex: 'id'
},{
header: "Name",
width: 220,
sortable: true,
dataIndex: 'name'
},{
header: "Code",
width: 220,
sortable: true,
dataIndex: 'code'
},{
header: "Note",
width: 250,
sortable: true,
dataIndex: 'note'
}
],
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
region: 'center',
xtype: 'grid',
id: 'my_grid',
autoScroll: true,
layout: 'fit',
iconCls:'icon-grid'
})

function myload(){
myGridStore.load();
}

myload()

Store.load() not working =(
i debug with firebug - data is empty.
cun't understand relations between Store, Record, Reader and Grid.
examples and tutorials working good but i still can't understand =(
how load informations from ajax result?
how load this information to store?

p.s. if somebody from russia can talk in icq - 133733457

thanks.
my brains are fu&ked for last 2 days =(

Animal
4 Apr 2008, 7:18 AM
You need a JsonReader. DataReader is abstract.

mjlecomte
4 Apr 2008, 9:23 AM
Once you change your reader, don't forget to specify the 'root'.