44

I've been using jQuery DataTables plugin ( http://datatables.net ) for quite some time and usually we're super fine using the default sizes and using "bStateSave": true option.

But now I really need to set the sizing of the pagination not as [10,25,50,100] but rather I need this as let's say [1,2,3]. I get the menu to set like this with setting the option aLengthMenu:[1,2,3] and if I select one of the options, it sets the correct selection amount.

But on dataTable STARTUP it doesn't set the length to 1,2,3 but rather to the default '10'.

Which option am I missing?

starball
  • 20,030
  • 7
  • 43
  • 238
Sam
  • 16,435
  • 6
  • 55
  • 89

3 Answers3

65

clear your cookies, the ones datatables saved when you were using bStateSave and you had 10,25,50,100

then refresh and it should now save 1 or 2 or 3

do you mean

"aLengthMenu": [[5, 10, 15, 25, 50, 100 , -1], [5, 10, 15, 25, 50, 100, "All"]],
"iDisplayLength" : 10,
max4ever
  • 11,909
  • 13
  • 77
  • 115
  • Thanks upfront, only changing aLengthMenu didn't have any effect today (didn't use bStateSave at that time), so i will try with iDisplayLength tomorrow. I will let you know and then vote/accept, thank you upfront! – Sam Nov 08 '11 at 18:33
  • 7
    Great, thank you. `iDisplayLength` is the Option for setting the initial Amount of Datarows to display. Thanks a lot! – Sam Nov 09 '11 at 07:28
43
  • DataTables 1.10+

    Use lengthMenu to define a list of available page lengths and optionally pageLength to set initial page length.

    If pageLength is not specified, it will be automatically set to the first value given in array specified by lengthMenu.

    var table = $('#example').DataTable({
       "lengthMenu": [ [2, 4, 8, -1], [2, 4, 8, "All"] ],
       "pageLength": 4
    });
    

    See this jsFiddle for code and demonstration.


  • DataTables 1.9

    Use aLengthMenu to define a list of available page lengths and iDisplayLength to set initial page length.

    var table = $('#example').dataTable({
       "aLengthMenu": [ [2, 4, 8, -1], [2, 4, 8, "All"] ],
       "iDisplayLength": 4,        
    });
    

    See this jsFiddle for code and demonstration.

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
  • *For DataTables below 1.10 please see the unaccepted answer* This one is the more current version and therefore should be accepted now – Sam Oct 07 '15 at 07:01
1

Make sure to wait, until you angular things load.

$timeout(function(){ // given timeout for wait load the page
   $('#dataTables-example').dataTable({
        "iDisplayLength": 10, 
   });
}, 100, false);