Is it possible to have datatables accept json in a column?

Is it possible to have datatables accept json in a column?

max_favillimax_favilli Posts: 4Questions: 0Answers: 0
edited May 2012 in General
I have a table with 20 columns where at the end I just make 2 columns visible with dynamically crafted html during "fnRender", I use the other 18 columns content to build the html using "o.aData[n]" inside the "fnRender".

I was wondering, can't I return a structured JSON object as column 0 and just use it in fnRender for column 1 and 2, avoiding to return 20 columns?

I know it's still JSON and it's not going to change much in terms of bandwidth but at least I don't have to put useless html markup in the page, and I can have a more simple aoColumns array.

Is it possible?

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Possibly yes actually with the way DataTables 1.8+ works. What you would do is set sDefaultContent for the columns where you won't be returning any data, and then when you want to add it in future, use fnUpdate .

    I've never tired it, but I don't see any reason why that wouldn't work :-)

    Allan
  • max_favillimax_favilli Posts: 4Questions: 0Answers: 0
    Hi Allan,

    I endedup doing the following:
    [code]
    "fnServerData": function (sSource, aoData, fnCallback) {
    jQuery.ajax({
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function (a, b, c) {
    _t.slug = a.bbData;
    delete a.bbData;
    fnCallback(a,b,c);
    }
    });
    },
    [/code]

    I send all the data I require for formatting as new proprty bbData and remove it before to pass it to fnCallback, I store bbData in an array within the class and since bbData and aaData have the same lenght and are sorted the same I just read it using the index in my "fnRender" functions.

    Hope it help others.

    Thanks for the support.
    Max
This discussion has been closed.