【问题标题】:Jquery Datatables slow render on IE9Jquery Datatables 在 IE9 上渲染缓慢
【发布时间】:2014-12-05 10:59:18
【问题描述】:

我在将大量数据加载到数据表 (jquery) 时遇到问题。 虽然 Chrome / Firefox 中的加载时间是可以接受的(大约 2 秒),但我的应用程序需要在 IE9 中运行,其中加载时间约为 16 秒。
我尝试使用 "bDeferRender" : true,但没有任何成功。
此数据表在 tfoot 中具有选择过滤器,并且每当用户选择列中的值时,都需要更新所有其他过滤器。此外,所有行的第一列都有一个复选框,让用户选择一行。

数据表初始化:



        var tableApi;              
        var initFunction = function(){
            tableApi = this.api();
            setTimeout(function(){
                preventFirstDraw = false;
            },5000);
            tableApi.columns().indexes().flatten().each( function ( colIdx ) {
                if(colIdx>0){
                    var column = tableApi.column( colIdx );
                    if(colIdx-1')
                            .appendTo( $(column.footer()).empty() )
                            .on( 'change', function () {
                                var val =  $(this).val();
                                var columnInside = tableApi.column( colIdx );
                                columnInside
                                    .search( val ? '^'+val+'$' : '', true, false )
                                    .draw();
                                bindTableClick(id,index);
                                var nextColIdx = colIdx+1;
                                $("select[data-colIdx='"+nextColIdx+"']").each(function(){
                                    var select = $(this);
                                    select.empty();
                                    tableApi.rows().data().each( function ( d, j ) {
                                        if(d[colIdx].toLowerCase() == val.toLowerCase() || $.trim(val)==""){
                                            select.append( ''+d[nextColIdx]+'' );
                                        }
                                    } );

                                });
                            } );
                        column.data().unique().sort().each( function ( d, j ) {
                           select.append( ''+d+'' )
                    });
                    }else{
                        $( 'input', column.footer() ).on( 'keyup change', function () {
                            oTable
                                .column( colIdx )
                                .search( this.value )
                                .draw();
                            bindTableClick(id,index);
                        } );
                    }
                }
            } );
        };
        var oTable = table.DataTable({
            "language": dataTableFR,
            "aaSorting": [[0, 'asc']],
            "iDisplayLength": 10,
            "bDeferRender" : true,
            "initComplete": initFunction
        });


bindTableClick 函数:



        function bindTableClick(id,index){
                Metronic.init();         
                $('#'+id+" tbody tr").unbind('click');          
                $("#"+id+" tbody tr").click( function(){
                    if($(this).hasClass("active")){
                        $(this).removeClass("active");
                        $(this).find('.checkboxes').each(function(){
                            $(this).attr('selected', false);
                            $(this).parent().removeClass('checked');
                            $(this).trigger('change');
                        });
                        var headers = $(this).parents('table').find('th').map(function() {
                            return $.trim($(this).attr('data-alias'));
                        }).get();
                        var values = $(this).find('td').map(function() {
                            return "";
                        }).get();
                        updateComponentTableValue(headers,values);
                    }else{
                        $("#"+id+" tbody tr").removeClass("active");
                        $("#"+id+" tbody tr .checkboxes").each(function(){
                            $(this).attr('selected', false);
                            $(this).parent().removeClass('checked');
                            $(this).trigger('change');
                        });
                        $(this).addClass("active");
                        $(this).find('.checkboxes').each(function(){
                            $(this).parent().addClass('checked');
                            $(this).attr('selected', true);
                            $(this).trigger('change');
                        });
                        var headers = $(this).parents('table').find('th').map(function() {
                            return $.trim($(this).attr('data-alias'));
                        }).get();
                        var values = $(this).find('td').map(function() {
                            return $.trim($(this).text());
                        }).get();
                        updateComponentTableValue(headers,values);
                        triggerComponent(index,"");
                    }
                });
                $('#'+id+' .group-checkable').change(function () {

                    var set = jQuery(this).attr("data-set");
                    var checked = jQuery(this).is(":checked");
                    jQuery(set).each(function () {
                        if (checked) {
                            $(this).attr("checked", true);
                            $(this).parents('tr').addClass("active");
                        } else {
                            $(this).attr("checked", false);
                            $(this).parents('tr').removeClass("active");
                        }                    
                    });
                    jQuery.uniform.update(set);
                }); 
        }

【问题讨论】:

  • 所以这些必须包含一大堆数据。 这么多 数据对最终用户有多大用处?您不能提供渲染时间更短的分页数据吗? 2 秒是一个时代……在手机上会是什么样子?
  • 该应用程序只能在 IE9/Intranet 上运行,我需要一次所有数据来执行查询。
  • 您是否需要渲染所有数据来执行这些查询?
  • 是的,数据来自存储过程,我需要所有数据来构建选择过滤器

标签: javascript jquery datatable internet-explorer-9 jquery-datatables


【解决方案1】:

这是我的数据表配置:

   var dataTable = $('#users').dataTable(
            {
            "sAjaxSource": "users/complete_list", /* Contains one thousand of users which are charged in few seconds */
            "deferRender": true,
            "bProcessing": true,
            "bServerSide": true,
        }

    );

试试看,告诉我是否适合你。 ^^

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-17
  • 2020-12-06
  • 2012-01-18
  • 2014-10-08
  • 1970-01-01
  • 2011-11-16
相关资源
最近更新 更多