datatable and json

datatable and json

nicolas69nicolas69 Posts: 11Questions: 0Answers: 0
edited February 2013 in DataTables 1.8
hi,
I'm a noob in javascript and php.

I'm trying to use datatable with ajax.But it's not working.

Here is my code:

[code]
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "get_data.php"
} );
} );

[/code]

Here is my return of json in get_data.php:

[code]{"sEcho":0,"iTotalRecords":"37","iTotalDisplayRecords":"37","aaData":[[" TREXOTIQUE","488480070","mr name","","BOX 20 Kva",null,"60 MOIS","FRED","","","RETRACTE",""],["WYYWICH","789352598","mr name","","BOX 10KVA",null,"60 MOIS","FRED","","","gh",""],["CAPUCINNO GOUR","507606333","mr name","","BOX 10KVA",null,"60 MOIS","FRED","2125,53","06\/02\/2013","",""],["LEEDIVE","514718675","M mr name","","BOX 20 Kva",null,"60 MOIS","FRED","2125,53","06\/02\/2013","",""],["TARIA OLES","535231583","mr name","","BOX 10KVA",null,"60 MOIS","FRED","","","",""]]}[/code]

and my html table:

[code]


[/code]

my page is blank there is nothing

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Firstly, do you really need server-side processing? IT should only be needed for 50'000+ rows (20'000+ if you are using older IE versions). If not, then don't use it as it adds complexity. If you do need it, then you need to fully implement the server-side processing protocol which is described here ( http://datatables.net/usage/server-side ) - your current implement ion has two errors that I see immediately - sEcho should never be 0, and iTotalRecords / iTotalDisplayReocrds are not integers in your return.

    Allan
  • nicolas69nicolas69 Posts: 11Questions: 0Answers: 0
    edited February 2013
    hi Allan, thanks for your quick response.
    I'm wondering now if i really need ajax to get my data from my DB...
    I think i will have about 5000 rows.
    Is it possible to add rows with ajax, i mean i want to add row and my table display new rows without refreshing the page?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited February 2013
    For 5000 rows us Ajax loading with deferred rendering: http://datatables.net/release-datatables/examples/ajax/defer_render.html .

    And yes, you can use fnAddData to add rows on the client-side.

    Allan
This discussion has been closed.