当使用fnAdjustColumnSizing时,数据表没有被调整大小

DataTable(s) are not getting resized when using fnAdjustColumnSizing

本文关键字:调整 数据表 fnAdjustColumnSizing      更新时间:2023-09-26

我的应用程序有左窗格和右窗格。右窗格有多个选项卡,每个选项卡包含一个数据表。

如果用户只想查看右窗格,我提供了展开右窗格的能力,因此,每当展开右窗格时,我需要展开我的数据表。

我目前正在使用下面的代码来扩展/折叠数据表,但这似乎不能正常工作。只有一个数据表(当前显示在屏幕上的表)被正确调整大小,其他表没有被正确调整大小。

有人能帮我解决这个问题吗?
function onCollapse(e) {
  var table = $.fn.dataTable.fnTables(true);
    if ( table.length > 0 ) {
        setTimeout(function () {
            for(var i=0;i<table.length;i++){
                $(table[i]).dataTable().fnAdjustColumnSizing();
            }
        }, 200);
    }
}
function onExpand(e) {
    var table = $.fn.dataTable.fnTables(true);
    if ( table.length > 0 ) {
        setTimeout(function () {
            for(var i=0;i<table.length;i++){
                $(table[i]).dataTable().fnAdjustColumnSizing();
            }
        }, 200);
    }
}

谢谢,Barani

好的,我想到了一个解决这个问题的方法。

我在(kendo tabstrip)选项卡的激活事件上添加了以下代码,这解决了问题。

    function onActivate(e) {
        var table = $.fn.dataTable.fnTables();
        if ( table.length > 0 ) {
            setTimeout(function () {
                for(var i=0;i<table.length;i++){
                    $(table[i]).dataTable().fnAdjustColumnSizing();
                }
            }, 200);
        }
    }

谢谢,Barani