简体   繁体   English

在数据表中呈现的性能问题

[英]Performance issues with rendering in datatables

I am trying to render around 2500 rows with sorting disabled and "bDeferRender": true. 我试图渲染大约2500行禁用排序和“bDeferRender”:true。 It's taking around 40s in chrome(v27). 它需要大约40秒的铬(v27)。 I am using Datatables 1.9 and jquery 2. Any suggestions? 我正在使用Datatables 1.9和jquery 2.有什么建议吗?

Datatable settings for my datatable: 我的数据表的数据表settings

var oSettings = {
    'bDestroy': true,
    "bInfo": true,
    "bProcessing": true,
    "bDeferRender": true,
    'iDisplayLength': 10,
    'sPaginationType': 'full_numbers',
    'sDom': '<"top"i> T<"clear">lfrtip',
    'sPageButtonActive': "paginate_active",
    'sPageButtonStaticDisabled': "paginate_button",
    "oLanguage": {
        "sSearch": "Futher Filter Search results:",
        "sInfo": "Got a total of _TOTAL_ results to show (_START_ to _END_)",
        "sLengthMenu": 'Show <select>' +
                '<option value="5">5</option>' +
                '<option value="10">10</option>' +
                '<option value="15">15</option>' +
                '<option value="20">20</option>' +
                '<option value="25">25</option>' +
                '</select> results'
    },
    "bSort": false
};

Quick guess: you are using fnAddData like this oTable.fnAddData(cells) , once for each row. 快速猜测:你正在使用类似于oTable.fnAddData(cells) ,每行一次。 This will cause the DataTable to redraw after each addition. 这将导致DataTable在每次添加后重绘。 Add a second parameter, false , eg, oTable.fnAddData(cells,false) . 添加第二个参数false ,例如, oTable.fnAddData(cells,false) Then after your loop, call oTable.fnDraw() . 然后在循环之后调用oTable.fnDraw() This will redraw only once instead of 2500 times. 这将只重绘一次而不是2500次。

See this fiddle: http://jsfiddle.net/V2Kdz/ 看到这个小提琴: http//jsfiddle.net/V2Kdz/

Click the "Populate" button to populate the table. 单击“填充”按钮以填充表格。

Line 12 is: 第12行是:

var ai = t.fnAddData(cells,false);

With the redraw parameter false, the table draws in under one second (on my mid-2011 Mac Air). 如果redraw参数为false,则表格会在一秒钟之内(在我2011年中期的Mac Air上)。 If you set the redraw parameter to true (or remove it, as the default is true), it takes over one minute. 如果将redraw参数设置为true(或删除它,因为默认值为true),则需要一分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM