【问题标题】:Second row header for fixed column in datatable数据表中固定列的第二行标题
【发布时间】:2016-01-05 03:15:54
【问题描述】:

我需要实现具有固定列的 3 行标题。所以我将标题行附加到 dataSrc 回调的标题中。下面是我如何在标题中添加行。

       function createHeaders(headeData){

       //.... creating firstHeaderRow
       //.... creating secondHeaderRow
            $('thead tr:first-child').before(firstHeaderRow);
            $('thead tr:last-child').after(secondHeaderRow);
       }

我的表配置如下:

       $('#tableElement').DataTable({
           fixedColumns : {
               leftColumn: 5,
               rightColumn: 2
           },
           ajax:  {
               dataSrc: function(data){
                    createHeaders(data.headerData);
                }
           }
       });

问题是在这种情况下,固定列的 firstHeaderRow 和 secondHeaderRow 没有显示。 (它正确显示了非固定列)

根据文档,我认为我需要调用 fnRedrawLayout()

所以我在 createHeaders 函数底部添加了以下行

        var table = $('#tableElement').dataTable();
        var fc = new $.fn.dataTable.FixedColumns( table,  {
             leftColumn: 5,
             rightColumn: 2
        });
        fc.fnRedrawLayout();

但是我在 FixedColumn.min 上收到此错误

       Uncaught TypeError: Cannot read property 'style' of null on below line.

       a.wrapper.style.height=e+"px";0<this.s.iLeftColumns&&(a.left.wrapper.style.width=g+"px",a.left.wrapper.style.height="1px",a.left.body.style.height=

非常感谢任何帮助以使其正常工作。

【问题讨论】:

  • 您使用的是什么版本的数据表和固定列?也许尝试在重绘之前调用columns.adjust(),但在添加标题行之后? datatables.net/reference/api/columns.adjust()
  • DataTable.version = "1.10.10" 和 FixedColumns.version = "3.2.0"
  • 我在调用 fc.fnRedrawLayout() 之前添加了 columns.adjust();但没有用。我仍然收到样式错误。我添加了标题行而不是列,不确定您为什么建议调整列。
  • 您添加的标题行是否没有按列分隔?我通常会在初始化数据表之前构建我的复杂标题,所以我从来没有尝试过在之后添加它们。您是否尝试过致电:fixedColumns().relayout()rows().recalcHeight()fixedColumns().update()?从这个页面:datatables.net/reference/api/#fixedcolumns
  • @chrisvanhooser 非常感谢。你让我的一天 table.columns.adjust().fixedColumns().relayout();工作!

标签: javascript jquery datatables


【解决方案1】:

解决方案是致电columns.adjust()fixedColumns().relayout()

这允许数据表了解您在构建后添加的标题行。

固定列扩展也需要更新所有更改,因为它基本上创建了一个新表以放置在实际表的顶部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    相关资源
    最近更新 更多