Getting JSON object

Getting JSON object

sulestsulest Posts: 2Questions: 0Answers: 0
edited September 2013 in DataTables 1.8
Hello,

I have a bit of silly question. How to get whole JSON response.
Why? Because I'm trying to create table headers that will be selectboxes so my code is:

My JSON looks like this
[code]
{"aaData":
[
["INT","INT","STRING","STRING","STRING","STRING","STRING"],
["INT","INT","STRING","STRING","STRING","STRING","STRING"],
["INT","INT","STRING","STRING","STRING","STRING","STRING"]
],

"sEcho":1,
"iTotalRecords":"19",
"iTotalDisplayRecords":"9",
"orderNumbers":["1","3","6","7"],
"productNames":["NAME","OTHER NAME","NNNAME"]
}
[/code]


[code]
oTable = $('.datatable').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"iDisplayLength" : 30,
"iMaxPageLength" : 100,
"bScrollInfinite": true,
"sAjaxSource": URL,
"aaSorting": [[0,"desc"]],
"aoColumnDefs":[
{"bSearchable": false, "bVisible": false, "aTargets":[0]},
{"bSortable": false, "aTargets":[1,2,3,4,5,6]}
],

"fnHeaderCallback": function(nHead, aaData, iStart, iEnd, aiDisplay){
//how to call OBJ.orderNumbers or OBJ.productNames
//I NEED JSON RESPONCE HERE
//SO I WILL BE ABLE TO CHANGE SOME STUF IN TABLE HEADER
}
[/code]

I have information about how to pull aditional request and get my aditional data, but I do not want to make 2 requests every time.
I need to get orderNumbers and productNames

Thanks

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Its a bit of a hack, but you could try:

    [code]
    var json = $.parseJSON( this.fnSettings().jqXHR.responseText );
    [/code]

    in the header callback.

    DataTables saves the XHR object, but not the JSON reply. An oversight that - I'll add it in to the new API for 1.10.

    Allan
  • sulestsulest Posts: 2Questions: 0Answers: 0
    Thank you Allan, you are a lifesaver.
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    In fact, 1.10 has this method already in git :-).

    Allan
This discussion has been closed.