【问题标题】:DataTables menu for select items to show per page doesn't work用于选择每页显示的项目的 DataTables 菜单不起作用
【发布时间】:2018-04-26 02:57:41
【问题描述】:

在我的 DataTable 上,您可以选择每页要显示多少项目的框不起作用。它向我展示了这个: [[5,10],[5,10]] 只显示数字。 我试图了解导致此问题的原因,但没有成功。

如果我单击菜单选项之一,我也会遇到此错误:Showing NaN to NaN of 2 entries

我在我的 Rails 4 应用程序中使用它。

这是我的 js:

var dtMainDataTable;            // Reference to main table
var dtSecondaryDataTable;   // Reference to secondary table
var dtTertiaryDataTable;    // Reference to tertiary table
var dtMainOrder;          // Main table ordering

/*
* Create tables on document ready
*/
$(document).ready( function() {

  // Set the order of the main table and update if overridden by page.
  dtMainOrder = [0, 'asc'];
  if (typeof dtMainOrderUpdate !== 'undefined') {
    dtMainOrder = dtMainOrderUpdate;
  }

  dtMainDataTable = $('#main').DataTable({
    columnDefs: [],
    "pageLength": pageLength,
    "lengthMenu": pageSettings,
    "order": dtMainOrder,
    responsive: true
  });

  dtSecondaryDataTable = $('#secondary').DataTable({
    columnDefs: [],
    "pageLength": pageLength,
    "lengthMenu": pageSettings,
    responsive: true
  });       

  dtTertiaryDataTable = $('#tertiary').DataTable({
    columnDefs: [],
    "pageLength": pageLength,
    "lengthMenu": pageSettings,
    responsive: true
    });

});

/**
 * Show all items in the main table. 
 * Really only for testing purposes.
 *
 * @return [Null] 
 */
function dtMainTableAll() {
  dtMainDataTable.page.len(-1).draw();
}

【问题讨论】:

  • 你需要使用 paginate:true 和 paginatetype : full_numbers 属性
  • 我必须在我使用表格的视图中包含那些? @sridharreddy
  • 我添加了那些我仍然有同样问题的人

标签: javascript jquery ruby-on-rails datatables


【解决方案1】:

我解决了自己的问题,希望对其他人有用。 我的代码中有这个:var pageLength = '#{current_user.table_rows}'; 我删除了''并重新开始工作 所以对我有用的结果是: var pageLength = #{current_user.table_rows};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多