【发布时间】: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