Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display page length at the bottom of table

All,

I am using Jquery Data Tables. I am using the following example:

DataTables with Pagination

I was wondering if there's a way to display "Show 10 Entries" on the bottom instead of top. It should be displayed right before "Showing 1 to 10 of 51 entries".. at the bottom of the table.

How can I do that?

Thanks

like image 405
Jake Avatar asked Jun 27 '10 18:06

Jake


People also ask

What is page length in Datatable?

The pageLength option is used to specify the number of rows of the table that are to be displayed on one page. This option is relevant when the pagination is used to display many rows. It accepts an integer value that denotes the number of rows to be displayed.

What is lengthChange in Datatable?

The lengthChange option is used to specify whether the dropdown to change the number of rows per page is displayed or not. This dropdown is shown only when paging of the DataTable is enabled, as disabling it automatically removes the dropdown. A true value displays the dropdown and a false value removes it.

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 pageLength?

pagelength statement controls where page breaks occur. The report formatter subtracts the number of lines in the footer (specified in the . footer page section of the specifications) from the total page length of nlines. Page length is the total number of body text lines for the page.


2 Answers

The way to do that is to change the sDom in the .js, where you define the table:

$('#TABLE_ID').dataTable({`
    "sDom": 'Rfrtlip'`    
 });

Additionally, you should change the .css to appear next to the "Showing ... entries", because this way it appear above it.

This is the explanation of the sDom options:

The following options are allowed:

  • 'l' - Length changing
  • 'f' - Filtering input
  • 't' - The table!
  • 'i' -Information
  • 'p' - Pagination
  • 'r' - pRocessing

The following constants are allowed:

  • 'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')
  • 'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')

The following syntax is expected:

  • '<' and '>' - div elements
  • '<"class" and '>' - div with a class
  • '<"#id" and '>' - div with an ID Examples:
  • '<"wrapper"flipt>' 'ip>'

PS: This could also help you:

datatables sDom

add-datatables-length-at-the-bottom-of-the-table

like image 196
tsveti_iko Avatar answered Sep 19 '22 01:09

tsveti_iko


Had a similar problem (wanted to remove some unnecessary controls) and the only way to deal with it seems to be modifying table yourself. I used fnDrawCallback callback (http://datatables.net/usage/callbacks).

It will be something like this in your case

$('#tableId').dataTable({
    "fnDrawCallback": function () {
        $('#tableId_info').prepend($('#tableId_length'));
    }
});

Just check the generated code in that demo, it's really quite simple (except it has no formatting or indentation).

You can also use class names instead of ids, if you're not afraid to affect other tables on the page. They're in the form dataTables_length.

Use css for additional styling.

like image 39
Nikita Rybak Avatar answered Sep 20 '22 01:09

Nikita Rybak