page.len()

Since: DataTables 1.10

Get / set the table's page length.

Description

This method is used quite simply to get and set the length of the paging used by DataTables for display. Please note that this is only relevant when paging is enabled in the table.

The special number -1 can be used as a set parameter, and returned by the get format of this function to indicate that all rows in the DataTable will be displayed.

Please be aware that this method sets the page to be shown - it does not actually perform the re-display of the table. In order to have the newly set page shown use the draw() method, which can be called simply as a chained method of the page() method's returned object - for example table.page( 0 ).draw();.

Types

function page.len()

Description:

Get the page length of the table. Note that if multiple tables are available in the API's context, the page length of the first table in the context will be used. Use table() if you are working with multiple tables in a single API context.

Returns:

Current page length. Note that -1 indicates that all records are shown.

function page.len( set )

Description:

Set the page length to be used for the display

Parameters:
Returns:

DataTables API instance

Example

Allow user to click on two elements to select if all records should be shown or just 10.:

var table = $('#example').DataTable();

$('#all').on( 'click', function () {
	table.page.len( -1 ).draw();
} );

$('#_10').on( 'click', function () {
	table.page.len( 10 ).draw();
} );

Related

The following options are directly related and may also be useful in your application development.