Datatable jump to specific page on load


Topic: Datatable jump to specific page on load

NitinMistry pro premium asked 8 months ago

Hi,

I would like to jump to a specific page when the DataTable is loaded, specifically the last page as after adding a new row to the bottom of the table list, I would like to navigate to that page to show the user that the newly added record is available in the list.

How do I achieve this?


Mikołaj Smoleński staff answered 8 months ago

Hi there,

The easiest way is to trigger click event just after initialization or data update. Here's the example code:

  $('#dtBasicExample').DataTable();
  $('.dataTables_length').addClass('bs-select');
  let pageItems = $('#dtBasicExample_wrapper').find('.page-item');
  pageItems.last().prev().click();

Best regards


NitinMistry pro premium answered 8 months ago

Thanks Mikołaj. This works perfectly fine.

On a side note, how do I remove sorting on specific columns? Right now the DataTable has sorting on all columns and I can't seem to figure out how to remove from specific ones on which I do not want any sorting.


Mikołaj Smoleński staff answered 8 months ago

Hi there again,

For this moment sorting works in the simplified way. You can only turn it on or off for the whole table.

Best regards


NitinMistry pro premium answered 8 months ago

Too bad. Anyway, thanks for the reply Mikołaj.


Please insert min. 20 characters.
Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: jQuery
  • MDB Version: 4.6.0
  • Device: Desktop
  • Browser: Chrome 71.0.3578.98 (64-bit)
  • OS: Windows 8.1
  • Provided sample code: No
  • Provided link: No
Tags