Filter/pagination issue
Filter/pagination issue
Hi,
I have an issue with custom server-side filtering leading to confusing table behaviour.
Alongside the table, I have several checkboxes that alter the query behaviour when selected. The unaltered query is also used to generate a count of the total and so what I would expect to see would be something like
"Showing 1 to 8 of 8 entries (filtered from 2,176 total entries)"
This works fine when I'm on the first paginated page, but if the page * items per page is higher than the number of filtered items then the table is empty, the page remains unchanged and the message reads (for page 5, in this case):
"Showing 41 to 8 of 8 entries (filtered from 2,176 total entries)"
Is there any way to force a page change when total filtered objects is greater than (page * items per page)?
Thanks,
Steve
I have an issue with custom server-side filtering leading to confusing table behaviour.
Alongside the table, I have several checkboxes that alter the query behaviour when selected. The unaltered query is also used to generate a count of the total and so what I would expect to see would be something like
"Showing 1 to 8 of 8 entries (filtered from 2,176 total entries)"
This works fine when I'm on the first paginated page, but if the page * items per page is higher than the number of filtered items then the table is empty, the page remains unchanged and the message reads (for page 5, in this case):
"Showing 41 to 8 of 8 entries (filtered from 2,176 total entries)"
Is there any way to force a page change when total filtered objects is greater than (page * items per page)?
Thanks,
Steve
This discussion has been closed.
Replies
DataTables version: 1.7.6 and 1.8
Browser - Firefox 3, Firefox 4 (others not tested at this point)
Initialisation code is below. Note that #{...} and ${...} syntax is from Groovy
[code]
var fnServerData = function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "tableId",
"value": "${_tableId}" } );
if (typeof clientAjaxParameters != 'undefined')
{
clientAjaxParameters(aoData);
}
#{get 'ajaxParameters' /}
$.getJSON( sSource, aoData, function (json) {
if (typeof json.errorMessage != 'undefined') {
window.alert(json.errorMessage);
}
fnCallback(json)
});
}
${_tableId}DataTable = $('#${_tableId}').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'lfrtip<"customiseTable">',
"sAjaxSource": "${_dataSource}",
"bProcessing": true,
"bServerSide": true,
"bSort": false,
"aoColumns": columnModel,
"aoColumnDefs": [ {
"fnRender": function ( oObj ) {
var result = // some tweaking here to add hyperlinks to the td elements
return result;
},
"aTargets": [ "_all" ]} ],
"fnServerData": fnServerData,
"aaSorting": [],
"oLanguage": {
"sSearch": "&{'filter'}"
}
});
[/code]
For completeness, the code that adds the checkbox selection to the AJAX call (referenced with clientAjaxParameters above) is
[code]
function clientAjaxParameters(aoData)
{
$('.osf').each(function()
{
aoData.push( { "name": $(this).attr('name'),
"value": $(this).attr('checked') } );
});
}
[/code]