Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change results per page value in datatables

Datatables has an option to select the number of records shown per page. The default value starts from 10, 25, 50 and 100. How can I change it to start from 5 instead of 10? 10 records is a bit too much and takes a lot of space in my current design. Thanx!

http://datatables.net/

like image 647
detj Avatar asked May 20 '10 07:05

detj


People also ask

How do I show only 5 records in a DataTable?

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

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

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

How does DataTables pagination work?

DataTables can split the rows in tables into individual pages, which is an efficient method of showing a large number of records in a small space. The end user is provided with controls to request the display of different data as the navigate through the data.

How many rows of content are displayed per page of a table by default?

By default, data table diplays 10 rows per page.


2 Answers

The fully correct answer would be to use both and display length to 5:

$(document).ready( function(){     $('#table').dataTable({     "iDisplayLength": 5,     "aLengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]]     }); }); 

If you use JUST "iDisplayLength", then the dropdown will not have that length in options later or when the page loads (instead you will see the first option, IE 10 by default). If you JUST use "aLengthMenu", then your results will still default to 10 instead of the first menu option.

like image 71
TheFrack Avatar answered Sep 23 '22 01:09

TheFrack


You will want to use the iDisplayLength parameter when you initialize the DataTable object. Here's the example they list in their documentation:

$(document).ready( function() {     $('#example').dataTable( {         "iDisplayLength": 50     } ); } ) 

More information can be found here: http://www.datatables.net/usage/options

like image 26
seneyr Avatar answered Sep 20 '22 01:09

seneyr