change sDom parameter
change sDom parameter
In want to change the display on my datatable so that if the number of rows per page in more than 25 the pagination will appear also on top of the table. I change the number of rows per page from my own control and I tried doing it like this:
[code]
$('#change_iDisplayLength').live('click', function() {
if ($('#iDisplayLength').val() != display_length && parseInt($('#iDisplayLength').val()) > 0) {
display_length = $('#iDisplayLength').val();
sDom = '';
if (parseInt(display_length) >= 25) {
sDom = '';
}
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = parseInt($('#iDisplayLength').val());
oSettings._sDom = sDom;
oTable.fnPageChange("first", false);
oTable.fnDraw();
}
});
[/code]
But it is not working, the top pagination control does not appear even thou if I look in the table settings it does have the new value.
Thanks,
Virgil
[code]
$('#change_iDisplayLength').live('click', function() {
if ($('#iDisplayLength').val() != display_length && parseInt($('#iDisplayLength').val()) > 0) {
display_length = $('#iDisplayLength').val();
sDom = '';
if (parseInt(display_length) >= 25) {
sDom = '';
}
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = parseInt($('#iDisplayLength').val());
oSettings._sDom = sDom;
oTable.fnPageChange("first", false);
oTable.fnDraw();
}
});
[/code]
But it is not working, the top pagination control does not appear even thou if I look in the table settings it does have the new value.
Thanks,
Virgil
This discussion has been closed.
Replies
[code]
$(document).ready(function() {
$('#example').dataTable( {
// change the drop down list
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
// set the initial value
"iDisplayLength": 50
} );
} );
[/code]
see http://www.datatables.net/ref#aLengthMenu
Set up sDom to have the pagination at the top and the bottom of the table ( http://datatables.net/release-datatables/examples/advanced_init/dom_multiple_elements.html ) and then use the fnDrawCallback function to look at the table and see how many rows there are displayed (http://datatables.net/plug-ins/api#fnPagingInfo or standard DOM/jQuery methods) - if there are >=25 rows, then set display:block for the top pagination element, for <25 rows, set display:none.
Allan