DataTable handling different format of json

DataTable handling different format of json

babablacksheepbabablacksheep Posts: 41Questions: 23Answers: 0
edited March 2014 in DataTables 1.9
I am new to Datatables and trying to figure out this problem. I have a server which oupts json in certain format(see below).I cant change that on server side.

**Note: I am using link http://www.json-generator.com/j/cftupHnpbC?indent=4 to emulate my server response just for checking.

I have 2 problems
[quote]
1 - Since My json response doesn't have aaData: thing required by dataTable, I cant seem to initiliaze it.
Even if I add aaData: by hand to json just for checking, dataTable cant count total records.
2 - How I can set that manually ?Since I cant change output from server.
[/quote]

JSBIN LINK: http://live.datatables.net/dasuyaf/1/edit

[code]




ID
Name
Text




[/code]

[code]
$(document).ready( function () {
var table = $('#example').dataTable({
"sAjaxSource": "http://www.json-generator.com/j/cftupHnpbC?indent=4",
"aoColumns": [{
"mData": "id",
"mRender": function (data, type, full) {
return '';
}
}, {
"mData": "id"
}, {
"mData": "name"
}, {
"mData": "text"
}],
"bProcessing": true,
"bServerSide": true,
"sServerMethod": "GET",
"aoColumnDefs": [{
'bSortable': false,
'aTargets': [0]
}],
"fnDrawCallback": function (oSettings) {
console.log(this.fnSettings().fnRecordsTotal());
}
});
});
[/code]

[code]
[
{
"text": "Some text",
"name": "somedata",
"id": "89"
},
{
"text": "Some text",
"name": "somedata",
"id": "2"
},
{
"text": "Some text",
"name": "somedata",
"id": "12"
}
]
[/code]

Replies

  • allanallan Posts: 63,490Questions: 1Answers: 10,470 Site admin
    > 1 - Since My json response doesn't have aaData: thing required by dataTable, I cant seem to initiliaze it.

    Use sAjaxDataProp and set it to be an empty string.

    > 2 - How I can set that manually ?Since I cant change output from server.

    Don't - see above :-)

    Allan
  • babablacksheepbabablacksheep Posts: 41Questions: 23Answers: 0
    Ok. Thank You.It works.
This discussion has been closed.