using server-side, structured JSON and fnRender

using server-side, structured JSON and fnRender

flippyheadflippyhead Posts: 11Questions: 0Answers: 0
edited March 2011 in General
I'd like to send over more than just values in an array, but instead send over more structured json that can be processed using something like fnRender into HTML for each column/row. So rather than sending, say, a text URL like "http://example.com" I'd like to send {url: "http://example.com", name: "exmpale"} then parse that into example.

So, behind each row would be a full JSON object, only some sub-portion of which would be used to generate the datatable contents.

Is this possible?

Thank You

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi flippyhead,

    It's a good question, and I'm afraid I've not got an equally as good answer I'm afraid. The basic answer is that, no it isn't possible because the information that DataTables expects back from the server is a 2D array which will be displayed as is on the server. Being able to add abstract data like this is a key goal of the next big release of DataTables.

    However! There are two ways to do what you are looking for:

    1. You could serialise the JSON object and put that in the table cell - then when fnRender runs it will eval() the string and render the information out. Its perfectly workable although not exactly ideal as it adds a little overhead.

    2. You could use fnServerData ( http://datatables.net/usage/callbacks#fnServerData ) rather than fnRender, to intercept the data coming back from the server and construct the 2D data array from the JSON that the server returns - effectively creating your own rendering function. Personally I'd say this would be the way I would do it myself. There is an example of how to use fnServerData to intercept data here: http://datatables.net/plug-ins/server-data-formats#json_object - not exactly like what you are looking for, but hopefully a good start.

    Regards,
    Allan
This discussion has been closed.