Suggested Code Addition for Variable Pagination Lengths

Suggested Code Addition for Variable Pagination Lengths

jhilgemanjhilgeman Posts: 1Questions: 0Answers: 0
edited October 2009 in General
Instead of hardcoded pagination lengths (I needed specific page length options), maybe this should become a variable? I modified the following code and it works pretty well:

Added this under the this.aoColumns = []; definition (around line 921 or so):
[code]
/*
* Variable: aPaginationLengths
* Purpose: The different lengths available for pagination
* Scope: jQuery.dataTable.classSettings
*/
this.aPaginationLengths = [10,25,50,100];
[/code]

Inside the function _fnFeatureHtmlLength, I changed the sStdMenu variable definition to:

[code]
var sStdMenu =
'';
for( var i=0 ; i

Replies

  • allanallan Posts: 61,799Questions: 1Answers: 10,115 Site admin
    Hi jhilgeman,

    Or you could use the oLanguage.sLengthMenu parameter: http://datatables.net/usage/i18n#oLanguage.sLengthMenu . There is even an example showing how it could be done :-). Regardless, thanks for sharing your solution with us - it looks like quite a nice way of doing it.

    Regards,
    Allan
  • visvis Posts: 4Questions: 0Answers: 0
    edited October 2009
    We've noticed that DataTables always displays 10 rows at first by default. We've changed that into 100 by using:
    [code]
    var oSettings = dataTable.fnSettings();
    oSettings._iDisplayLength = 100;
    dataTable.fnDraw();
    [/code]

    Just after: var dataTable = $('.DataTableGridView').dataTable(); block. But the user still sees that there are 10 rows and afterwards there are more. The problem is that we have only list of 50, 100, 250 and "all" in drop down by changing language variable since 10 is just too small for us.

    Is it possible to define default value for startup somewhere at setup?
  • allanallan Posts: 61,799Questions: 1Answers: 10,115 Site admin
    Hi vis,

    You can just use the iDisplayLength ( http://datatables.net/usage/options#iDisplayLength ) initialisation property to set the number of records to be shown on a page at initialisation. This will work correctly with the drop down menu as well (as long as you have either defined your custom value in the menu, or it is one of the defaults).

    Regards,
    Allan
This discussion has been closed.