1

I am trying to fill a Datatable with a JSON using YUI,

I have this JSON:

[{"test":"value1",
"test2":"value2",
"test3":"value3",
"topic_id":"123139007E57",
"gmt_timestamp":1553994442,
"timestamp_diff":-1292784933382,
"status":"images\/statusUp.png",
"device_id":"568FDE9CC7275FA"}, ..

It continues like this with about 20 different devices, and I close it with a ]

I just want to print select keys in the datatable so my Column Definitions look like this:

var myColumnDefs = [
    {key:"test", sortable:true, resizeable:true},
    {key:"test2", sortable:true, resizeable:true},
    {key:"topic_id", sortable:true, resizeable:true},
    {key:"status", sortable:true, resizeable:true},
    {key:"device_id", sortable:true, resizeable:true},
];

var myDataSource = new YAHOO.util.DataSource(bookorders);
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource.responseSchema = {
            fields: ["test","test2","topic_id","status","device_id"]
        };


    var myDataTable = new YAHOO.widget.DataTable("basic",
            myColumnDefs, myDataSource);

It's print Data Error for some reason, what am I doing wrong?

Thanks!

I have tested the validity of the JSON at JSONLint and it says it is valid.

Doug Molineux
  • 12,283
  • 25
  • 92
  • 144
  • If you're using JSON, I think your datasource response type should be of that type: YAHOO.util.DataSource.TYPE_JSON instead of TYPE_JSARRAY. Have you looked at the example in: http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html – Javi Jan 06 '11 at 19:01
  • Thank you for your advice, I scrapped this example, used the example you provided, replaced the queries, filenames, response schema, column definitions, still a data error. I'm not sure what I'm doing wrong for some reason it doesn't seem to like my JSON – Doug Molineux Jan 06 '11 at 19:49
  • Can you use Firebug to see exactly which is the error? See if the response is OK and which json is returned. If you think its a problem of the json you can use a library like Jackson to generate it in the server (it will make sure that the json is ok). – Javi Jan 07 '11 at 15:32
  • It turns out my JSON wasn't working with the YUI Json interpretter for whatever reason, I have got this working though, Javi if you respond with an answer I'll mark it correct, Thanks! – Doug Molineux Jan 07 '11 at 16:15

1 Answers1

2

If you're using JSON, I think your datasource response type should be of that type: YAHOO.util.DataSource.TYPE_JSON instead of TYPE_JSARRAY. Have you looked at the example in: developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html

Can you use Firebug to see exactly which is the error? See if the response is OK and which json is returned. If you think its a problem of the json you can use a library like Jackson to generate it in the server (it will make sure that the json returned is ok).

Javi
  • 19,387
  • 30
  • 102
  • 135