简体   繁体   English

jQuery数据表-首先显示最后一页

[英]jQuery Datatables - Show Last Page First

I am using the jQuery DataTables plugin ( https://datatables.net/ ). 我正在使用jQuery DataTables插件( https://datatables.net/ )。 I am trying to get the last page to be the first page. 我正在尝试使最后一页成为首页。 I am sorting by date and would like the latest entries to be at the bottom of the visible area. 我正在按日期排序,希望最新条目位于可见区域的底部。

So if the "Records per page:" is 10, then the latest date should be at the bottom. 因此,如果“每页记录数:”为10,则最新日期应在底部。 I am using the plugin to create a "logbook" so the latest entries should always be at the bottom. 我正在使用该插件创建“日志”,因此最新条目应始终位于底部。 I have tried the following but I can't get it to work: 我尝试了以下方法,但无法正常工作:

jQuery jQuery的

// On page load: datatable
var table_companies = $('#table_companies').dataTable({

    "ajax": "data.php?job=get_companies",
    "sDom": '<"top"lB><"clear">rt<"bottom"p><"clear">',
    "language": {
     "paginate": {
      "previous": "Older Entries"
      }
     },

    "autoWidth": false,
    "searching": true,
    "columns": [
      { "data": "date" },
      { "data": "type",   "sClass": "company_name" },
      { "data": "registration" }

      ],
    "aoColumnDefs": [
      { "bSortable": false, "aTargets": [-1] }
    ],
    "lengthMenu": [[5, 10, 25, 50, 100], [5, 10, 25, 50, 100]],   
    "pagingType": "simple",
    "oLanguage": {

      "sLengthMenu":    "Records per page: _MENU_",
      "sInfo":          "Total of _TOTAL_ records (showing _START_ to _END_)",

      "sInfoFiltered":  "(filtered from _MAX_ total records)"
  }
});
  table_companies.fnPageChange( 'last' );

I am using this link to load my plugin: 我正在使用此链接加载我的插件:

<script type="text/javascript" src="https://cdn.datatables.net/t/dt/dt-1.10.11,b-1.1.2,b-colvis-1.1.2,b-print-1.1.2,cr-1.3.1,r-2.0.2/datatables.min.js"></script>

请检查以下代码:

$('#datatable').DataTable().page('last').draw('page');

It turns out it was as simple as capitalizing the "D" in dataTables. 事实证明,这就像在dataTables中大写“ D”一样简单。

Changed: 已更改:

var table_companies = $('#table_companies').dataTable({

to: 至:

var table_companies = $('#table_companies').DataTable({

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM