0

我有一个 jquery 数据表在 Firefox 和 chrome 上运行良好,但在 IE7 上运行速度很慢。我正在使用数据表版本 1.7.6。

这是有 9 列的表:

this.dataTable = $('#sar-requests-table').dataTable({
    "aaSorting": [[ 4, "desc" ]],
    "aoColumnDefs": [{
        "fnRender": function ( row ) {
            return renderWorkOrderIdTableCell(row.aData[0]);
         },
         "aTargets": [0]
     }],
     "bProcessing": true,
     "bJQueryUI": true,
     "oLanguage": {
         "sSearch": "Filter:"
     }
});

当我调用 fnReloadAjax 插件时会发生缓慢。

 this.dataTable.fnReloadAjax("/api/sar/?_=" + Math.random() + "&" + query);

此调用对 Java EE 应用程序进行查询,并带来最多 5000 条记录。我调试了插件并指出了需要花费大量时间的地方:

$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource,      fnCallback,bStandingRedraw)
{
if ( typeof sNewSource != 'undefined' && sNewSource != null )
{
    oSettings.sAjaxSource = sNewSource;
}
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
var iStart = oSettings._iDisplayStart;

 console.log('STEP 1 '+new Date());

oSettings.fnServerData( oSettings.sAjaxSource, null, function(json) {
    /* Clear the old information from the table */
    that.oApi._fnClearTable( oSettings );

    console.log('STEP 2 '+new Date());

    /* Got the data - add it to the table */
    for ( var i=0 ; i<json.aaData.length ; i++ )
    {
        that.oApi._fnAddData( oSettings, json.aaData[i] );
    }
    console.log('STEP 3 '+new Date());

    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();

    that.fnDraw( that );

    console.log('STEP 4 '+new Date());

    if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
    {
        oSettings._iDisplayStart = iStart;
        that.fnDraw( false );
    } 

    console.log('STEP 5 '+new Date());

    that.oApi._fnProcessingDisplay( oSettings, false );

    /* Callback user function - for event handlers etc */
    if ( typeof fnCallback == 'function' && fnCallback != null )
    {
        fnCallback( json );
    }

    console.log('STEP 6 '+new Date());
} );
}

大部分时间花在(STEP2和STEP3)和(STEP3和STEP4)之间,总共30秒(如果有5000条记录)。意思是,下面的块需要15秒;

for ( var i=0 ; i<json.aaData.length ; i++ )
    {
        that.oApi._fnAddData( oSettings, json.aaData[i] );
    }

下面的一个需要另外 15 秒:

    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    that.fnDraw( that );

这两个块都需要不到一秒钟的时间。在 Firefox 和 chrome 上。我还尝试删除表格上的排序和单元格渲染,但没有帮助。当我输入“bpaginate:false”时,我看到了更好的性能,但它不是 5000 条记录的选项。

任何建议表示赞赏。

编辑:我尝试使用 1.8.0 和 1.9.1 版本,但它们都没有帮助。

4

0 回答 0