PDA

View Full Version : URL read problem with Grouping store (AJAX related)



radtad
1 Feb 2008, 3:40 PM
Ok, so I cant seem to figure out why the data won't load in this script. It returns data from the url in an array format. If there is thread out there with this info please point me in the right direction ( I can't seem to find one at this point).



Ext.onReady(function(){

Ext.QuickTips.init();

var xg = Ext.grid;

// shared reader
var reader = new Ext.data.ArrayReader({}, [
{name: 'date', type: 'date', dateFormat: 'd/m/Y'},
{name: 'job'},
{name: 'task'},
{name: 'linenum', type: 'float'},
{name: 'name'},
{name: 'uname'},
{name: 'location'},
{name: 'hours', type: 'float'}
]);

var grid = new xg.GridPanel({
store: new Ext.data.GroupingStore({
proxy: new Ext.data.HttpProxy({
method: 'POST',
url: "/blah",
}),
reader: reader,
sortInfo:{field: 'date', direction: "ASC"},
groupField:'date'
}),

columns: [
{id:'date',header: "Date", width: 60, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'date'},
{header: "Job", width: 20, sortable: true, dataIndex: 'job'},
{header: "Task", width: 20, sortable: true, dataIndex: 'task'},
{header: "LineNum", width: 20, sortable: true, dataIndex: 'linenum'},
{header: "Name", width: 20, sortable: true, dataIndex: 'name'},
{header: "User Name", width: 20, sortable: true, dataIndex: 'uname'},
{header: "Location", width: 20, sortable: true, dataIndex: 'location'},
{header: "Hours", width: 20, sortable: true, dataIndex: 'hours'}

],

view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),

frame:true,
width: 700,
height: 450,
collapsible: true,
animCollapse: false,
title: 'Grouping Example',
iconCls: 'icon-grid',
renderTo: document.body
});

grid.load();
});



Also, I can't seem to make this data display using an AJAX function call. Any suggestions on how to return the data correctly into the grid?

Thanks

halkon_polako
2 Feb 2008, 10:37 AM
From ArrayReader docs: "Data reader class to create an Array of Ext.data.Record objects from an Array". So, ArrayReader needs an array object, not a string representation of an array, what I guess is what you have.
Use a JsonReader instead.
Just for no guessing: can you post the response that you have?

radtad
5 Feb 2008, 11:23 AM
Yeah, I think you were right. I was returning an array, but I think it was reading it in as a string. So I changed the read to JSon and it works now. Thanks!