change sDom parameter

change sDom parameter

virgilvirgil Posts: 12Questions: 0Answers: 0
edited December 2011 in General
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

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited November 2011
    You should set up the drop down list like this:

    [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
  • virgilvirgil Posts: 12Questions: 0Answers: 0
    I don not have a dropdown list, I've hidden that and I am using a textbox where the user writes the number of rows per page he want's to see, that's what i'm doing in the above.
  • virgilvirgil Posts: 12Questions: 0Answers: 0
    So, can I do this in any way? I just need to have the pages div both before and after the table if the number of elements per page is more than a defined number, and just after the table if it's not.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > 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.

    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
  • virgilvirgil Posts: 12Questions: 0Answers: 0
    thanks, somehow, I did not think of that, thou I did the same for hiding the pagination if there was only one page.
This discussion has been closed.