Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82495

DataTable handling different format of json

$
0
0
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

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.


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

 
<table id="example" class="display" width="100%">
  <thead>
    <tr>
      <th> </th>
      <th>ID</th>
      <th>Name</th>
      <th>Text</th>
    </tr>
  </thead>
  <tbody></tbody>
</table>


 
$(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 '<input type="checkbox" name="chkids[]" value="' + data + '">';
      }
    }, {
      "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());
    }
  });
});


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

Viewing all articles
Browse latest Browse all 82495

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>