PDA

View Full Version : Data not showing in my data grid



zurik44
3 May 2007, 4:09 PM
Hello fellow Ext Guru's, I have a little issue where my data is not loading into my grid. This is my first attempt at using the grid I'm going to attach as much info as I can but if I leave anything out please post what I need to send you to help troubleshoot my issue.

The following is the code for loading my grid.



<script language="javascript">

Ext.onReady(function(){

// create the Data Store
var ds = new Ext.data.Store({
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.HttpProxy({
url: '/administrator/userManager/ajax.userlist.cfm'
}),

// create reader that reads the Topic records
reader: new Ext.data.JsonReader({
root: 'DATA',
id: 'ID'
}, [
{name: 'ID', mapping: 'ID'},
{name: 'First Name', mapping: 'FIRSTNAME'},
{name: 'Last Name', mapping: 'LASTNAME'},
{name: 'Username', mapping: 'USERNAME'},
]),

// turn on remote sorting
//remoteSort: true
});
//ds.setDefaultSort('LASTNAME', 'asc');
ds.load();

// custom or reusable ColumnModels
var colModel = new Ext.grid.ColumnModel([
{header: "ID", width: 25, sortable: true, locked:false, dataIndex: 'ID'},
{header: "Firs Name", width: 75, sortable: true, dataIndex: 'FIRSTNAME'},
{header: "Last Name", width: 75, sortable: true, dataIndex: 'LASTNAME'},
{header: "Username", width: 85, sortable: true, dataIndex: 'USERNAME'}
]);

// create the Grid
var grid = new Ext.grid.Grid('user-grid', {
ds: ds,
cm: colModel,
});

grid.render();

});

</script>



As you can see it's pretty text book.
My ajax.userlist.cfm file is pretty simple. The output of the file is below. I am using the JSONEncode UDF from Cflib.org to convert my query to a JSON String.



{"RECORDCOUNT":3,"COLUMNLIST":"FIRSTNAME,ID,LASTNAME,USERNAME,UUID","DATA":{"FIRSTNAME":["Marco","Guest","Developer"],"ID":[1,2,6],"LASTNAME":["Williams","Account","Developer"],"USERNAME":["admin","guest","dev"],"UUID":["171C6E58-BCD6-41DB-F9A60055B09C5FE0","171DEDE3-BCD6-41DB-F6AA30EE46189D95","1745385C-BCD6-41DB-FDCD9A738A6FE065"]}}


Attached are firebug screen shots to aid in your evaluation of my issue.

This is all i get in my grid :(
http://beta.bluapple.net/images/griderror.jpg


I'm no expert, however I do think this is a very strait forward "example" I just don't understand what I'm doing wrong.

Any help would be great!

Thanks,
Marco ( a.k.a Zurik )

fay
3 May 2007, 4:21 PM
Marko,,

I did spot an additional , after your reader entry for USERNAME



{name: 'Username', mapping: 'USERNAME'},
]),


and



cm: colModel,

The flamin' things are getting me all the time!

jsakalos
3 May 2007, 4:23 PM
I haven't analyzed your code fully but for the first glance it seems to me that you load ds too early.

Construct everything first, then grid render an ds.load() last.

Try...

zurik44
3 May 2007, 9:56 PM
jsakalos, I tried, prior to the original post, loading the the ds.load(); after rendering, that did not seem to solve the issue.

fay, I'll look into the comma's and see if that solves anything.

Both jsakalos & fay thank you very much for your input!

zurik44
3 May 2007, 10:03 PM
Nope that did not do the trick, I removed the comma and still no data. Any other suggestions?

zurik44
3 May 2007, 10:04 PM
jsakalos, i also moved the ds.load so that it is after the render. That also did not solve the issue. Any further help would be awesome!

Animal
3 May 2007, 11:08 PM
Your data is in the wrong format.

You supply an Array of seperate ROW objects, not COLUMN objects. See example code and documentation.

Also, you supply the total record count, but don't instruct the JsonReader to use it. Again, see documentation.

Animal
3 May 2007, 11:08 PM
Also, the dataIndex references the field's name

zurik44
4 May 2007, 10:50 AM
Animal, thank you for your input, You might have been right! I finally got fed up with JSON and went with the XMLReader instead. Funny thing was I was having the same issue with the XML reader. But that, after hours troubleshooting and browsing the forums, was because I had to set the Header Content-Type to text/xml. That has resolved my issue.

As for JSON, I kinda gave up on it for now and will revisit it later.

I want to reach out to eveyone that posted here and thank you again for your input. It helped me a great deal in my troubleshooting efforts. Anyone that wants to know how I got this issue resoved please feel free to email me at marco@kiwidaddy.com and I will be happy to explain further.

-={Marco}=-
"I can do anything and anything I can't do I can learn" - http://www.Dangerous-Minds.net