PDA

View Full Version : create grid from json url



digy79
30 Jun 2009, 7:45 AM
Hi all,

May be this is banal, but I don't understand how to populate a Grid starting from the json response returnet from this URL...

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5/query?text=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&where=SUB_REGION+%3D+%27Mountain%27&returnGeometry=false&outSR=&outFields=&f=pjson

Thanks a lot in advance!

digy79
2 Jul 2009, 5:01 AM
I'm managing to solve the problem.
I obtain the correct number of rows... but they are empty.
I can imagine there's something wrong with my JsonReader configuration, but I don't understand exactly what.

I really appreciate any suggestion, thanks guys...



Ext.onReady(function() {

//URL var
var URL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5/query?where=SUB_REGION+%3D+%27Mountain%27&returnGeometry=false&outFields=ObjectID,SUB_REGION&f=json"


/*GRID CONSTRUCTION
************************/

//Data returned from the REST service

//Data Store
var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({url:URL, method:'GET'}),
reader: new Ext.data.JsonReader({root:'features', id:'ObjectID'}, [
{name: 'ObjectID'},
{name: 'STATE_NAME'},
{name: 'SUB_REGION'}
])
});
ds.load();

//Column Model
var colModel = new Ext.grid.ColumnModel([
{header: "ID", width: 100, sortable: true, dataIndex: 'ObjectID'},
{header: "State", width: 100, sortable: true, dataIndex: 'STATE_NAME'},
{header: "Sub Region", width: 100, sortable: true, dataIndex: 'SUB_REGION'}
]);

//Grid
var grid = new Ext.grid.GridPanel({
el: 'grid-example',
ds: ds,
cm: colModel,
height:150,
autoScroll:true
});

grid.render();
grid.getSelectionModel().selectFirstRow();
Ext.get('grid-example').show();

});