Data tables paginate bug
Data tables paginate bug
joao.r.silva
Posts: 2Questions: 0Answers: 0
Hi Everyone.
I just had a problem with the pagination when in server side.
The problem was that although I was sending the total number of records correctly but pagination would think I had just 1 page, thus not enabeling.
Looking thought the code I saw that the value used to make proper pagination only works when you send all the records of the table, therefore I corrected the problem like this.
At the top of the function I added the following code
function _fnPageChange ( oSettings, sAction )
{
var effectiveRecords =0
if ( oSettings.oFeatures.bServerSide ) {
effectiveRecords=oSettings.fnRecordsTotal();
} else {
effectiveRecords=oSettings.fnRecordsDisplay();
}
In the same function I changed the code for Next and Last buttons as in:
else if ( sAction == "next" )
{
if ( oSettings._iDisplayLength >= 0 )
{
/* Make sure we are not over running the display array */
if ( oSettings._iDisplayStart + oSettings._iDisplayLength < effectiveRecords )
{
oSettings._iDisplayStart += oSettings._iDisplayLength;
}
}
else
{
oSettings._iDisplayStart = 0;
}
}
else if ( sAction == "last" )
{
if ( oSettings._iDisplayLength >= 0 )
{
var iPages = parseInt( (effectiveRecords-1) / oSettings._iDisplayLength, 10 ) + 1;
oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
}
else
{
oSettings._iDisplayStart = 0;
}
}
Also I changed code in the function:
"fnUpdate": function ( oSettings, fnCallbackDraw ) {
...
var iPages=0;
if ( oSettings.oFeatures.bServerSide ) {
iPages = Math.ceil((oSettings.fnRecordsTotal()) / oSettings._iDisplayLength);
} else {
iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
}
Then it works fine.
I don't know what people want to do to correct the problem and I think my code could be a little more elegant. I'm sending this just to tell what I deeded to do to correct it and help you guys to fix this bug.
Thanks to all
I just had a problem with the pagination when in server side.
The problem was that although I was sending the total number of records correctly but pagination would think I had just 1 page, thus not enabeling.
Looking thought the code I saw that the value used to make proper pagination only works when you send all the records of the table, therefore I corrected the problem like this.
At the top of the function I added the following code
function _fnPageChange ( oSettings, sAction )
{
var effectiveRecords =0
if ( oSettings.oFeatures.bServerSide ) {
effectiveRecords=oSettings.fnRecordsTotal();
} else {
effectiveRecords=oSettings.fnRecordsDisplay();
}
In the same function I changed the code for Next and Last buttons as in:
else if ( sAction == "next" )
{
if ( oSettings._iDisplayLength >= 0 )
{
/* Make sure we are not over running the display array */
if ( oSettings._iDisplayStart + oSettings._iDisplayLength < effectiveRecords )
{
oSettings._iDisplayStart += oSettings._iDisplayLength;
}
}
else
{
oSettings._iDisplayStart = 0;
}
}
else if ( sAction == "last" )
{
if ( oSettings._iDisplayLength >= 0 )
{
var iPages = parseInt( (effectiveRecords-1) / oSettings._iDisplayLength, 10 ) + 1;
oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
}
else
{
oSettings._iDisplayStart = 0;
}
}
Also I changed code in the function:
"fnUpdate": function ( oSettings, fnCallbackDraw ) {
...
var iPages=0;
if ( oSettings.oFeatures.bServerSide ) {
iPages = Math.ceil((oSettings.fnRecordsTotal()) / oSettings._iDisplayLength);
} else {
iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
}
Then it works fine.
I don't know what people want to do to correct the problem and I think my code could be a little more elegant. I'm sending this just to tell what I deeded to do to correct it and help you guys to fix this bug.
Thanks to all
This discussion has been closed.
Replies
iTotalRecords - Total records, before filtering (i.e. the total number of records in the database)
iTotalDisplayRecords - Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)
aaData - 2D array of data to be displayed, for this 'page' only.
So doesn't this do what you are looking for already?
Allan
The answer to your last question is no.
I my case the iTotalDisplayRecords in the pagination code is somehow ignored by the current dataTables code.
Here is a sample of my jason code that is returned to the DataTable.
[code]
{"sEcho": 1, "iTotalRecords": 44, "iTotalDisplayRecords": 10, "aaData": [["1","login","Sim"],["2","index","Sim"],["3","lojas","Sim"],["4","login/logout","Sim"],["5","gateway","Sim"],["6","pagamentos","Sim"],["7","formaspagamentoloja","Sim"],["8","formaspagamento","Sim"],["9","faturassituacoes","Sim"],["10","faturas","Sim"],]}
[/code]
In fact the databales code knows my request has a total of 44 records. For example in the show rows combobox it works fine, but the pagination doesn't. With this code the pagination is still disabled because the datatables thinks it has just one page.
This appens because on dataTables code line 485.
[code]
var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
[/code]
The number of pages is calculated using fnRecordsDisplay and not fnRecordsTotal.
Thanks
Joao
Allan
I have the same problem.
In a table with 25 rows and show 10 rows selected the pagination (i'm using full pagination) will only show one page.
The button next and last are disabled.
Picture http://screencast.com/t/NjMyZjgz
[code]
oaTable = $('#adminData').dataTable({
"aaSorting": [[0,'desc'], [1,'desc']],
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sAjaxSource": "includes/functions/getAdminInfo.func.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( oaTable.advancedSearch );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
} );
},
//var oaSettings = oaTable.fnSettings();
"fnDrawCallback": function ( oaSettings ) {
setupAdminTDClick(oaSettings);
},
"aoColumns": [
{
"bVisible": false
},
{
"sWidth": "50px",
"sClass":"setTDPadding"
},
{
"sWidth": "200px",
"sClass":"setTDPadding"
},
{
"sWidth": "200px",
"sClass":"setTDPadding"
},
{
"sWidth": "60%",
"sClass":"setTDPadding"
},
{
"sWidth": "24px",
"bSortable": false,
"sClass":"mySel"
}
]
});
[/code]
[code]
var oTable = $('#myTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "query/getQuery",
"bPaginate" : true,
"bLengthChange": true,
"bScrollCollapse" : true,
"iDisplayLength" : 20,
"bFilter" : true,
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"sSearch": "Search",
"sDom": '<"H"<"projectTeamTools">lrft>' // line A
});
$("div.projectTeamTools").html('Organize by Project Teams: ${projectTeam.projectName}');
[/code]
The dom is a custom div I have created to display a drop-down box.
The datatable does not show the paginate tool. It considers that I have passed only one page although my displayLength is 20 and the records fetched are greater than 20, it shows only 20 records.
But when I comment out the 'line A', the paginate tools are visible.
Is this wht problem with the functionality or the css?
Please help!
Most likely your server-side script isn't returning the required values for iTotalRecords and iTotalDisplayRecords: http://datatables.net/usage/server-side .
Can you use the debugger so I can confirm if this is the case ( http://debug.datatables.net ).
Allan
But in my case, it doesn't even display the tool when I display my sDom. But it displays the paginate if i disable my sDom. Is this the problem with css. If yes, could you please help me with it.
Also, I am facing a problem regarding the sDom. Could you please look in here (http://www.datatables.net/forums/discussion/9862/cannot-view-the-paginate-tool-at-the-bottom-of-the-table#Item_1).
Regards,
Sunmit.
And what was the debug code it gave you? Without that I can't access it :-).
Allan
Sunmit
Allan
~Sunmit
So as I say, without a link I can't say what is wrong with it.
Allan
~Sunmit
[code]"sDom": '<"H"<"projectTeamTools">lfrtp>'[/code]
Also, could you please help me on a problem I am facing here (http://www.datatables.net/forums/discussion/9862/cannot-view-the-paginate-tool-at-the-bottom-of-the-table#Item_1)
~Sunmit