PDA

View Full Version : JSONstore calling data but not being stored in Grid



tylerbell
8 Jul 2010, 11:14 AM
Hello All,

I've been having some trouble finding the problem in my code, so thought I'd try to find a second pair of eyes.


var logStore = new Ext.data.JsonStore({
autoLoad: true,
url: 'inc/interface/config.php?list=messages',
root: 'logs',
id: 'ID',
fields: ['ReceivedAt', 'Message']
});

var logGrid = new Ext.grid.GridPanel({
region: 'center',
store: logStore,
autoWidth: true,
height: 1000,
colModel: new Ext.grid.ColumnModel({
columns:[
{id: 'received', header: 'Received', dataIndex: 'ReceivedAt', width: 250},
{id: 'message', header: 'Logs', dataIndex: 'Message', width: 750}
]
}),
});


var mainViewport = new Ext.Viewport({
layout: 'border',
items:[logGrid, searchPanel]
});The code above is my interface, and while I am not getting any errors when loading up I just cannot get my data to store in the grid. I believe my store/grid is configured directly, but that's what I'm here for.

Below is the response I get from the store loading my code:

{"logs":[{"ID":"1","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:02 dh1 dhcpd: Added new forward map from blahhhhhhh to 10.193.blah.blah"},{"ID":"2","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:02 dh1 dhcpd: added reverse map from 248.240.blah.blah.in-addr.arpa. to blahhhhhhhh"},{"ID":"3","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:02 dh1 dhcpd: DHCPREQUEST for 10.193.blah.blah from aa:bb:cc:dd:ee:ff (blahhhhhh) via 10.193.blah.blah"}]}

Edited for obvious reasons.

Appreciate the help!

mankz
8 Jul 2010, 11:36 AM
1. Remove autoWidth, as the ViewPort manages this
2. Remove height, as the ViewPort manages this
3. Add listener for "exception" event on your store to find out about load errors

logStore.on('exception', function() { debugger;});

tylerbell
8 Jul 2010, 12:07 PM
I made the changes and added in the debugger. I'm not expert programmer so I'm not sure what it all means, but this is what I got in firebug:

this: Object data=Object removed=[0] autoLoad=true
scopeChain: [Call, Call mainViewport=Object logGrid=Object logStore=Object, Window interface.html 0=Call 1=Call 2=window]

fay
8 Jul 2010, 2:51 PM
Just a couple of wee things - not certain if they'll fix your problem.

1. Use idProperty instead of id in logStore.

2. Include 'ID' in the list of logStore fields.

3. Change your exception handler's parameter list to match:

exception (http://www.sencha.com/deploy/dev/docs/source/DataProxy.html#event-Ext.data.DataProxy-exception) : ( DataProxy this, String type, String action, Object options, Object response, Mixed arg )

and use put a breakpoint (with FireBug) within this and check the parameter values.

4. Watch out for the trailing comma at the end of your ColumnModel definition.

tylerbell
12 Jul 2010, 10:17 AM
I think I found the problem, but not sure how to fix it. While firebug shows that the PHP is correctly pulling data from the database, I do not believe it is being parsed correctly to be displayed on the Grid.

What I did was took out the "log" and just displayed the date and it worked fine; then I tried the log and it failed. The data is stored in mysql like:

Apr 9 00:00:02 dh1 dhcpd: Added new forward map from blah.wifi.blah to 10.193.blah.blah

(dhcp logs obviously)

I just don't think its getting parsed correctly on the JS side...is there anything I can do to the grid to correct this?