Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DataTables Pagination Size

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? Thanks in advance!

like image 205
Sam Avatar asked Nov 08 '11 13:11

Sam


People also ask

What is page length in Datatable?

The pageLength button acts in exactly the same way as the default length list and will inherit the options specified by the lengthMenu option. This example shows the pageLength button being used with lengthMenu to specify page lengths of 10, 25, 50 and all rows, with language strings used for the buttons.

How do I change the page length in a Datatable dynamically?

Use page. len() API function to change page length dynamically.

How do I display only 5 records in a Datatable?

There is a option called pageLength . You can set this for show only 5 entries.

What is Datatable pagination?

The paging option is used to specify whether the paging of the DataTable is enabled or not. The DataTable splits the records being shown in multiple pages so that only a certain number of records are shown on a page. The number of records to show can be selected using the dropdown menu.


2 Answers

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, 
like image 93
max4ever Avatar answered Sep 22 '22 05:09

max4ever


  • 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.

like image 44
Gyrocode.com Avatar answered Sep 21 '22 05:09

Gyrocode.com