tags:

views:

134

answers:

2

Hello All,

I've had this problem for awhile now, but I keep narrowing down the issue and I think I have main problem figured out now. While my JSONstore calls to the PHP correctly, and firebug does give me the correct data back from the database, it will not display in my grid.

I have a grid with only 2 columns a date, and an entry from a log. When I take out the log entry, the grid will display the date just fine, and when I just create an array with static data from the log then it will display fine in the grid as well. I think my JSONstore just isn't parsing the data correctly from the mysql tables.

My code is:

  var logStore = new Ext.data.JsonStore({
    autoLoad: true,
    url: 'inc/interface/config.php?list=messages',
    root: 'dates',
    idProperty: 'ID',
    fields: ['ID', 'ReceivedAt', 'Message'],
    listeners: {
                loadexception: function() {
                    console.log('load failed -- arguments: %o', arguments);
                }
        }
}); 

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

An example of the log entry it's pulling is:

| Apr 9 00:00:02 dh1 dhcpd: Added new forward map from nfxxxxich-PC.wifi-uhs.osu to 10.xxx.xx.248 |
| Apr 9 00:00:02 dh1 dhcpd: added reverse map from 248.xxxx.xxx.10.in-addr.arpa. to nxxxxxh-PC.wifi-uhs.osu |
| Apr 9 00:00:02 dh1 dhcpd: DHCPREQUEST for 10.xxx.xxx.248 from 00:x:5c:x:8c:xx (nxxxxh-PC) via 10.xxx.xxx.254 |
| Apr 9 00:00:02 dh1 dhcpd: DHCPACK on 10.X.XX.248 to 00:X:5c:X8c:XX (nXXXich-PC) via 10.193.XX.XXX |
| Apr 9 00:00:02 dh1 dhcpd: Added new forward map from XX.wifi-uhs.XXX to 10.X.X.242 |
| Apr 9 00:00:02 dh1 dhcpd: added reverse map from 242.X.193.X.in-addr.arpa. to X.wifi-uhs.XXX |
| Apr 9 00:00:02 dh1 dhcpd: DHCPREQUEST for 10.X.X.242 from 00:X:ce:X21:63 (elena) via 10.X.X.254 |
| Apr 9 00:00:02 dh1 dhcpd: DHCPACK on 10.193.XXX.XX to 00:X:ce:X:21:63 (elena) via 10.X.X.254 |
| Apr 9 00:00:02 dh1 dhcpd: Added new forward map from P305-XXX.wifi-uhs.XXX to 10.193.X.X |
| Apr 9 00:00:02 dh1 dhcpd: added reverse map from 21.241.X.X.in-addr.arpa. to P305-XXXX.wifi-uhs.XXX |

There are various different characters and tabs between the date, dh1, and the log entry itself. Could there be an issue with escaping these characters? I'm just not quite sure how it's done. Any help would be appreciated.

A: 

You haven't specified the type and format in fields. And I'm guessing that your php json implementation doesn't generate a javascript Date object.

So... try returning an unix timestamp and use this as fields:

fields: [
  {name: 'ID', type: 'int'},
  {name: 'ReceivedAt', type: 'date', dateFormat: 'Y-m-d H:i:s'},
  'Message'
]

Optionally you could also specify a dateFormat next to the type: 'date'. See the documentation for more info: http://www.sencha.com/deploy/dev/docs/?class=Ext.data.Field

WoLpH
I just looked back and saw that I posted the wrong store. Also the RecievedAt is separate from Message which is the details mentioned at the end of my post. Sorry about that, totally my fault.
TBell
Can you give an example of the json data that `inc/interface/config.php?list=messages` returns? Or are the rows that you posted above what the file is returning? If so, that's not json and it won't work with the `JsonStore`.
WoLpH
I posted it below, if you have an idea on how I could fix that, maybe by escaping the special characters(?), please let me know.
TBell
@TBell: I've modified the fields definition. It should work like this :)
WoLpH
A: 

{"dates":[{"ID":"18","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:03 dh1 dhcpd: added reverse map from 244.xxx.xxx.10.in-addr.arpa. to xxx.wifi-uhs.xxx"},{"ID":"19","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:03 dh1 dhcpd: DHCPREQUEST for 10.xxx.xxx.244 from 00:xx:f0:xx:d5:xxx (xxx) via xx.x.xxx.254"},{"ID":"20","ReceivedAt":"2010-07-07 11:37:42","Message":" [origin software="rsyslogd" swVersion="3.22.1" x-pid="5222" x-info="http://www.rsyslog.com"] (re)start"},{"ID":"21","ReceivedAt":"2010-07-07 11:37:42","Message":"WARNING: rsyslogd is running in compatibility mode. Automatically generated config directives may interfer with your rsyslog.conf settings. We suggest upgrading your config and adding -c3 as the first rsyslogd option."},{"ID":"22","ReceivedAt":"2010-07-07 11:37:42","Message":"the last error occured in /etc/rsyslog.conf, line 38"},{"ID":"23","ReceivedAt":"2010-07-07 11:37:42","Message":"warning: selector line without actions will be discarded"},{"ID":"24","ReceivedAt":"2010-07-07 11:37:42","Message":"CONFIG ERROR: could not interpret master config file '/etc/rsyslog.conf'. [try http://www.rsyslog.com/e/2123 ]"},{"ID":"25","ReceivedAt":"2010-07-07 11:37:42","Message":"Warning: backward compatibility layer added to following directive to rsyslog.conf: ModLoad imuxsock"}]}

Actually I found the problem and its not my code. I limited my PHP to only pull 19 records and it works, it's on that 20th record where I get a different type of log that it messes up on my grid and nothing will display. I think it has to do with the special characters within the log.

Either way, it's an error with Rsyslog, which is what I'm using to dump these into mysql. Not sure exactly how I could fix it through php/extjs.

TBell