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/
There is a option called pageLength . You can set this for show only 5 entries.
Use page. len() API function to change page length dynamically.
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.
By default, data table diplays 10 rows per page.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With