AJAX Source table displays all records not 10
AJAX Source table displays all records not 10
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.
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.
This discussion has been closed.
Replies
//"bServerSide": true,
.dataTable().fnDraw();
Allan
Is there another way to redraw my table without the AJAX plugin?
> 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
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