Jquery 数据表修复了 IE 9 中的列问题

标签 jquery css asp.net-mvc-4 internet-explorer-9 datatables

我正在使用 jquery ui tabs 在同一个 div 中并排显示两个网格。使用 jquery datatables 插件显示网格。 最近我在我的两个网格中添加了固定列 的功能,这使得 IE 9 随机表现得很奇怪。
这种行为完全随机发生,但发生在两个网格之一上,而不是同时发生在两个网格上。 IE 9 在水平滚动条上显示固定列部分。它看起来像下面这样:

enter image description here

其他网格显示如下所示:
enter image description here
有趣的是,如果您整理受影响的表格或在搜索文本框中输入一些字符,这个重叠部分会自动修复。
我搜索它并了解到 draw() 函数在这些操作上被调用,所以我尝试在 tab selection event 上手动调用此函数但是 didn '解决问题
下面是选项卡选择事件的JS代码:

$('#divEAMountDismountGridsTabs, #CurrentSpec').tabs(
    {
        select: function(event, ui)
        {
            // Do stuff here
            var tempDismount = $('#tblDismountAtt').DataTable();
            tempDismount.draw(false);

            var tempCurrentSpec = $('#tblCurrentSpec1').DataTable();
            tempCurrentSpec.draw(false);
        }
    });


下面是我写的关于数据表初始化的 JS(两个网格都有相同的属性,所以我只是复制第一个网格的初始化)。

/*DataTable Implementation*/
    var tableDismountAtt = $('#tblDismountAtt').dataTable(
    {
        "bFilter": true,
        "bInfo": false,
        "bDestroy": true,
        "bwidth": '100%',
        //"sDom": '<"top"f>',
        'iDisplayLength':5000,
        "order": [[2, "asc"]],
         dom: "Cfrtip",
         scrollY: "140px",
         scrollX: "100%",
         paging: false,
         scrollCollapse: true,
        "aoColumnDefs" : [
                        {'bSortable' : false, 'aTargets' : [ 0 ] , "width": "80px"}, //Switch to Dismount
                        {'bSortable' : false, 'aTargets' : [ 1 ], "width": "80px"}, //Parts Status
                        {'bSortable' : true, 'aTargets' : [ 2 ], "width": "80px"}, //Sales Code
                        {'bSortable' : true, 'aTargets' : [ 3 ] , "width": "60px"}, //Price
                        {'bSortable' : false, 'aTargets' : [ 4 ], "width": "60px"}, //Currency
                        {'bSortable' : true, 'aTargets' : [ 5 ], "width": "150px"}, //Sales Code Description
                        {'bSortable' : false, 'aTargets' : [ 6 ], "width": "80px"}, //Quantity
                        {'bSortable' : false, 'aTargets' : [ 7 ], "width": "380px"}, //Remarks
                        {'bSortable' : true, 'aTargets' : [ 8 ], "width": "80px"}, //    PSO Ref No.
                        {'bSortable' : false, 'aTargets' : [ 9 ], "width": "150px"}, //Model Sub Name
                        {'bSortable' : false, 'aTargets' : [ 10 ] , "width": "80px"}, //Value
                        {'bSortable' : false, 'aTargets' : [ 11 ], "width": "150px"}, //Date
                        {'bSortable' : true, 'aTargets' : [ 12 ]},
                        {'bSortable' : true, 'aTargets' : [ 13 ]},
                        {'bSortable' : true, 'aTargets' : [ 14 ]}
                    ]

    });
    /*Freezing Dismount Attachment Columns*/       
    new $.fn.dataTable.FixedColumns( tableDismountAtt, {leftColumns: 6, heightMatch: 'auto'});

最佳答案

问题的原因是第二个网格在隐藏时初始化,因此当它变得可见时,控件的对齐受到干扰。 JQuery Datatables官网也提到了这个东西。您可以从 here 中阅读所有详细信息.

为避免这种情况,您需要在网格显示/绘制时调用AdjustColumns函数。

我已经调用了这个函数两次:

  1. 当数据表初始化时
  2. 在网格上调用绘制函数时

(起初我只是在初始化时调用了这个函数,但是当我尝试使用它的智能搜索来过滤记录时,对齐再次受到干扰。)

下面是我对现在运行良好的数据表初始化代码所做的更改。

/*DataTable Implementation*/
    var tableDismountAtt = $('#tblDismountAtt').dataTable(
    {
        "bFilter": true,
        "bInfo": false,
        "bDestroy": true,
        "bwidth": '100%',
        //"sDom": '<"top"f>',
        'iDisplayLength':5000,
        "order": [[2, "asc"]],
         dom: "Cfrtip",
         scrollY: "140px",
         scrollX: "100%",
         paging: false,
         scrollCollapse: true,
         "fnInitComplete": function () 
         {
            this.fnAdjustColumnSizing(true);
         },
         "fnDrawCallback" : function(oSettings)
         {
            this.fnAdjustColumnSizing(false);
         },
        "aoColumnDefs" : [
                        {'bSortable' : false, 'aTargets' : [ 0 ] , "width": "80px"}, //Switch to Dismount
                        {'bSortable' : false, 'aTargets' : [ 1 ], "width": "80px"}, //Parts Status
                        {'bSortable' : true, 'aTargets' : [ 2 ], "width": "80px"}, //Sales Code
                        {'bSortable' : true, 'aTargets' : [ 3 ] , "width": "60px"}, //Price
                        {'bSortable' : false, 'aTargets' : [ 4 ], "width": "60px"}, //Currency
                        {'bSortable' : true, 'aTargets' : [ 5 ], "width": "150px"}, //Sales Code Description
                        {'bSortable' : false, 'aTargets' : [ 6 ], "width": "80px"}, //Quantity
                        {'bSortable' : false, 'aTargets' : [ 7 ], "width": "380px"}, //Remarks
                        {'bSortable' : true, 'aTargets' : [ 8 ], "width": "80px"}, //    PSO Ref No.
                        {'bSortable' : false, 'aTargets' : [ 9 ], "width": "150px"}, //Model Sub Name
                        {'bSortable' : false, 'aTargets' : [ 10 ] , "width": "80px"}, //Value
                        {'bSortable' : false, 'aTargets' : [ 11 ], "width": "150px"}, //Date
                        {'bSortable' : true, 'aTargets' : [ 12 ]},
                        {'bSortable' : true, 'aTargets' : [ 13 ]},
                        {'bSortable' : true, 'aTargets' : [ 14 ]}
                    ]

    });

注意:

  1. fnAdjustColumnSizing(true) => 调整所有网格/数据表的列大小,无论它们是可见的还是隐藏的。

  2. fnAdjustColumnSizing(false) => 仅为可见的网格/数据表调整列大小。

关于Jquery 数据表修复了 IE 9 中的列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30231041/

相关文章:

css - 如何将 CSS 变量值分配给 scss 变量或表达式

html - 元素 div 的水平滚动仅限于较大的 div

asp.net-mvc - 无法在 cshtml 中加载 ReportViewerForMvc 引用

c# - 如何建立这种 EF 关系?

.net - ASP.NET Web API(测试版)是否可以与最新的 Mono(稳定版)一起运行?

javascript - 用于显示和隐藏的 Javascript

javascript - 滚动到元素后突出显示该元素

jquery - 在网页中可靠且快速地播放音频的最佳方法?

php - Jquery,在每个循环中向数组添加值

jquery - 选择元素的id