{hero}

page()

Since: DataTables 1.10

Get / set the current page of the table.

Description

Paging is a core feature of DataTables, and this method provides external control over the page which the table is displaying. This can be useful if you want to provide custom paging controls for your table, external to the built-in paging control options or the paging plug-in options.

Note that if you attempt to show a page which does not exist using the set format of this method, DataTables will not throw an error, but rather reset the paging to the first page.

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( false );.

Additionally note that you should pass false or page as the first parameter to draw() to have it do a standing redraw. Without this parameter, draw() will do a full draw resulting in the paging being reset back to the first page!

Types

function page()

Description:

Get the current page of the table. Note that if multiple tables are available in the API's context, the current page index 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:

Currently displayed page number

function page( set )

Description:

Set the page to be displayed by the table

Parameters:
Returns:

DataTables API instance

Example

Custom paging controls for next / previous pages:

var table = new DataTable('#myTable');

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

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

Related

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