AJAX Source table displays all records not 10

AJAX Source table displays all records not 10

anaganag Posts: 48Questions: 2Answers: 7
edited September 2013 in General
I use AJAX to load a json array into my table, the json does validate

I initialize my table with this

[code]

$(function () {
if(jQuery().dataTable) {
var oTable = $('#thetable').dataTable({
"oLanguage": {
"sEmptyTable": "No data"
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource":'http://example.com/json.php',
"fnServerParams": function ( aoData ) {
aoData.push({ "name": "post_id", "value":'<?php echo $pageID; ?>' } );
},
"aoColumns": [
{ "mDataProp": "post_id","bSortable": false },
{ "mDataProp": "url" },
{ "mDataProp": "page_type" },
{ "mDataProp": "cat" },
{ "mDataProp": "tags" },
{ "mDataProp": "country_code" },
{ "mDataProp": "action_buttons","bSortable": false }
]
});

}
});
[/code]

I have compared the XHR from my website to the demo at http://datatables.net/release-datatables/examples/server_side/server_side.html

The query string parameters below are the same on my server and the demo, these are being sent to the server with datatables that I know.

sEcho:1
iDisplayStart:0
iDisplayLength:10

My response from the server in the beginning of the json file is

iTotalDisplayRecords: "54"
iTotalRecords: "54"
sEcho: 1

In the json array are all 54 rows of data.

I think what I need is deferred loading? http://datatables.net/release-datatables/examples/server_side/defer_loading.html

But there is no code example. Or is that not what I need? I've read over what I should be sending to the server, and what I should send back but can't figure out how to get 10 rows to display in my table with the json response.

Thanks in advance.

Replies

  • anaganag Posts: 48Questions: 2Answers: 7
    I also want to note that if I comment out bServerSide, it does show 10 rows and paginate correctly, however the fnDraw() functions stop working?


    //"bServerSide": true,
    .dataTable().fnDraw();
  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    Sounds like you haven't fully implemented server-side processing: http://datatables.net/usage/server-side

    Allan
  • anaganag Posts: 48Questions: 2Answers: 7
    I commented out bServerSide, I think fnDraw only works with the data being processed on the server. I ended up using the Ajax Reload plugin. I thought fnDraw worked even without server side processing.

    Is there another way to redraw my table without the AJAX plugin?
  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    fnDraw works with or without server-side processing as you say, but obviously is functionality a little different since it will get new data from the server when server-sid processing is enabled, and just uses the current data when not.

    > Is there another way to redraw my table without the AJAX plugin?

    When you say redraw - do you want to get the latest data from the server, or just redisplay current data? If the former, then yes, in 1.9- you need the plug-in (there is a built in method for 1.10 which does the same thing).

    Allan
  • anaganag Posts: 48Questions: 2Answers: 7
    I need to re query the server and get a new json file, I'm deleting and updating records with AJAX so the table has to be updated I assume by making a new call to the json file? What's the build in method in 1.10?
  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    fnDraw will not make an ajax call - that's what fnReloadAjax is for.

    1.10 (which is pre-beta) has an `ajax.reload()` method - but there is no documentation for it yet. I'm still writing it.

    Allan
This discussion has been closed.