Looking to a way to show the last page of a table

Use case: in an accounting ledger (a table), the traditional way to display is to show records chronologically from oldest to newest. And for the convenience, it is good to display the last page (the newest records) when showing the ledger (the table).

I could not find a way in the Knack Developer Docs nor in the community for a javascript.

I also tried the article below, and the result is not as expected (it shows a page with no records):
https://support.knack.com/hc/en-us/articles/360030953512-Is-it-possible-to-display-more-than-100-records-at-a-time-on-a-table-list-or-search-view-

Need your help with a Javascript.

The above javascript code misses the last line. Here is the revised version:

$(document).on('knack-view-render.view_xxx', function(event, view, data) {

//Only position the page if no previous filtering applied.
if (location.href.indexOf('?') == -1) {

   var totalRecords = view.pagination_meta.total_entries;
   var recsPage = view.pagination_meta.rows_per_page;
   var lastPage = Math.trunc((totalRecords - 1) / recsPage) + 1;

   location.hash = location.hash + "?" + view.key + "_page=" + lastPage;
}

});

 

Hi Tony, thank you very much. It works, and this is such a smart solution.