PDA

View Full Version : Generating Grids from JSON Code(using Rails)



brainfck
4 Aug 2009, 11:04 AM
Hi,

I am totally new to ExtJS.

I want to generate grids from JSON Code.

My JSON Code is:

{"Total": 1, "Users": [{"username": "admin", "name": "Musermann", "surname": "Max", "id": 1}]}My JavaScript Code is:


<script type="text/javascript">
Ext.onReady(function(){

Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '/admin/administration/users/list_data'}),

reader: new Ext.data.JsonReader({
root: 'Users',
id: 'id',
totalProperty: 'Total'
}, [
{name: 'username', mapping: 'username'},
{name: 'surname', mapping: 'surname'},
{name: 'name', mapping: 'name'}
]),
// turn on remote sorting
remoteSort: true
});

// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{id:'username',header: "Username", width: 100, sortable: true, dataIndex: 'username'},
{header: "Surname", width: 75, sortable: true, dataIndex: 'surname'},
{header: "Name", width: 75, sortable: true, dataIndex: 'name'}
],
stripeRows: true,
autoExpandColumn: 'username',
height:350,
title:'Alle Benutzer anzeigen'
});
grid.render('grid');
});
</script>
<div id="grid"></div>
The grids example gets rendered but without any content.
Can you help me or suggest me any good tutorial?

Best regards