使用按钮启用DataTable中的固定列 [英] Enable disable fixed column in DataTable using a button
本文介绍了使用按钮启用DataTable中的固定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我自己使用jquery DataTable创建了一个具有固定列的html表,参考这个例子就是
Myself created a html table with fixed columns using jquery DataTable with reference to This example as,
$(document).ready(function() {
var table = $('#example').DataTable( {
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false
} );
new $.fn.dataTable.FixedColumns( table, {
leftColumns: 2
} );
} );
更新:我自己尝试使用按钮启用/禁用固定列如这个小提琴所示,
UPDATE: Myself trying to enable/disable the fixed column using a button as given in this fiddle as,
var columnNumber = 2;
$('#ToggleColumns').click(function () {
if(columnNumber == 2)
{
columnNumber = 0;
}
else {
columnNumber = 2;
}
foo();
其中 foo()
包含要固定的columnNumber。根据按钮切换列号的正确语法是什么?
where the foo()
contains the columnNumber to be fixed. What is the correct syntax to toggle the column number based on the button?
推荐答案
通过使用 table.destroy();
方法解决数据和初始化新选项新列号。
It is solved by using table.destroy();
method of datatable and initializing new options with new columnNumber.
示例链接: http:// jsfiddle .net / eqsadgez / 1 /
请提供更好的方法。
这篇关于使用按钮启用DataTable中的固定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文