PDA

View Full Version : No data displayed with JSON and Gridpanel



wavedan
6 Aug 2010, 3:16 AM
I am having some problems, there is no data displayed within the GridPanel, although the JSON does seem to work correctly.

Code:



/*!
* Ext JS Library 3.2.1
* Copyright(c) 2006-2010 Ext JS, Inc.
* [email protected]
* http://www.extjs.com/license
*/
Ext.onReady(function(){

// sample static data for the store
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'registercompany.php?mode=listRegistercompany',
method : 'POST'
}),
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'totalCount',
id: 'company_id'
},[
{name: 'company_id'},
{name: 'company_name'},
{name: 'orgno'},
{name: 'firstname'},
{name: 'lastname'},
{name: 'address1'},
{name: 'address2'},
{name: 'postalcode'},
{name: 'postalarea'},
{name: 'phone1'},
{name: 'mobile'},
{name: 'fax1'},
{name: 'email'},
{name: 'www'},
{name: 'bankaccount'},
{name: 'password'},
{name: 'member_role'},
{name: 'activation_code'},
{name: 'activation_status'}
])
});
console.log(store.fields);
//store.load({params:{start:0, limit:50}});
store.load();
// create the Grid

var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{id:'company_id',header: 'ID:', width: 30, sortable: true, dataIndex: 'company_id'},
{header: 'Navn', width: 75, sortable: true, dataIndex: 'company_name'}

],
stripeRows: true,
autoExpandColumn: 'company_id',
// height: 300,
autoHeight:true,
width: 450,
title: 'Brukersteder',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});

// render the grid to the specified div in the page
grid.render('grid-example');

});


Output from registercompany.php:



{"response":{"value":{"items":[{"company_id":"4","company_name":"Teeeste","orgno":"987654321","firstname":"Test","lastname":"Anders","address1":"Oslo","postalcode":"1520","postalarea":"Moss","phone1":"987654321","mobile":"","fax1":"","email":"[email protected]","www":"","bankaccount":"987654321","password":"321","activation_status":"N"},{"company_id":"3","company_name":"Daniel","orgno":"123456789","firstname":"Anders","lastname":"Test","address1":"Bergen","postalcode":"1520","postalarea":"Moss","phone1":"123456789","mobile":"","fax1":"","email":"[email protected]","www":"","bankaccount":"123456789","password":"123","activation_status":"N"},{"company_id":"1","company_name":"Daniel's Lekesaker","orgno":"12345678","firstname":"Daniel","lastname":"Fjeldstad","address1":"Moss","postalcode":"1570","postalarea":"Dilling","phone1":"90909090","mobile":"","fax1":"","email":"[email protected]","www":"","bankaccount":"1080808080","password":"123","activation_status":"N"}],"total_count":3,"version":1}}}

Condor
6 Aug 2010, 3:25 AM
1. Your 'root' should be 'response.value.items'.
2. Your 'totalProperty' should be 'total_count'.

wavedan
6 Aug 2010, 3:29 AM
Thanks a lot, that worked!