简体   繁体   English

jQuery Datatables性能

[英]jQuery Datatables performance

I use jQuery with Datatables to display about 300 database rows. 我将jQuery与Datatables一起使用以显示约300个数据库行。 The table is on a jQuery UI dialog and is downloaded with an AJAX request. 该表位于jQuery UI对话框上,并与AJAX请求一起下载。 After the download I want to create jQuery UI Buttons on every row for edit and delete. 下载之后,我想在每一行上创建jQuery UI Buttons以进行编辑和删除。 This takes long time (on some 'weak' clients) and it's really annoying. 这需要很长时间(对于某些“弱”客户),这确实很烦人。 Is there a way to make it faster? 有没有办法使其更快? I tried INPUT type="button" and is a bit faster but ugly. 我尝试了INPUT type =“ button”,速度更快但很丑。 Any Ideas/Suggestions? 有任何想法/建议吗? Thank you in advance!!! 先感谢您!!!

EDIT the last 2 lines inserting the buttons here is some of the code: 编辑最后两行插入按钮,这里是一些代码:

    $('<div id="wdw1000frm"></div>').dialog({
        parent : '#wdw1000',
        autoOpen : false,
        closeOnEscape : false,
        height : 500,
        maxHeight : 500,
        minHeight : 500,
        minWidth : 700,
        position : [479, 68],
        title : 'Arrivals',
        width : 1000
    });
    DWM.showForm("1000", "arrivals", "Arrivals", "Arrivals");
    $("#wdw1000_tbl").dataTable({
        "bJQueryUI" : true,
        "bPaginate" : false,
        "bProcessing" : true,
        "bLengthChange" : false,
        "bFilter" : true,
        "bSort" : true,
        "bInfo" : false,
        "bAutoWidth" : false,
        "sScrollY" : "300px",
        "sDom" : "<\"H\"lfr>tS<\"F\"ip>",
        "fnInitComplete" : function() {
            this.fnSettings().oScroller.fnScrollToRow(64);
        },
        "bDeferRender" : false,
        "oLanguage" : {
            "sProcessing" : "Επεξεργασία...",
            "sLengthMenu" : "Δείξε _MENU_ στοιχεία",
            "sZeroRecords" : "Δεν βρέθηκαν στοιχεία που να ταιριάζουν",
            "sInfo" : "Εμφάνηση _START_ έως _END_ από _TOTAL_ στοιχεία",
            "sInfoEmpty" : "Εμφάνηση 0 έως 0 από 0 στοιχεία",
            "sInfoFiltered" : "(εφαρμογή φίλτρου σε _MAX_ συνολικά στοιχεία)",
            "sInfoPostFix" : "",
            "sSearch" : "Αναζήτηση:",
            "oPaginate" : {
                "sFirst" : "Πρώτη",
                "sPrevious" : "Προηγούμενη",
                "sNext" : "Επόμενη",
                "sLast" : "Τελευταία"
            }
        },
        "aaData" : [['168', '00:10-1', '1339708200', 'TRA 232', 'Sundsvall', 'SDL', '', '', '', '0', '', '0', '3', 'Cancelled', 'CAN', '<div class="Edit"></div>', '<div class="Delete"></div>'], 
                    ['169', '00:45-1', '1339710300', 'AEE 261', 'Varkaus', 'VRK', '', '', '', '0', '', '0', '5', 'New Time', 'NET', '<div class="Edit"></div>', '<div class="Delete"></div>'], 
                    ['170', '01:15-1', '1339712100', 'FPO 228', 'Indianapolis', 'IND', '', '', '', '0', '', '0', '5', 'Diverted', 'DIV', '<div class="Edit"></div>', '<div class="Delete"></div>'], 
    .
    .
    .
                    ['300', '08:10+1', '1339909800', 'LT 3620', 'Sao Joao', 'QSJ', '', '', '', '0', '', '0', '3', '', '', '<div class="Edit"></div>', '<div class="Delete"></div>']],
        "aoColumns" : [{
            "bVisible" : false
        }, {
            "aDataSort" : [2, 1],
            "sClass" : "alignLeft",
            "sTitle" : "STM",
            "sWidth" : "100px"
        }, {
            "bVisible" : false
        }, {
            "sClass" : "alignLeft",
            "sTitle" : "FN",
            "sWidth" : "100px"
        }, {
            "sClass" : "alignLeft",
            "sTitle" : "CITY"
        }, {
            "bVisible" : false
        }, {
            "sClass" : "alignLeft",
            "sTitle" : "VIA"
        }, {
            "bVisible" : false
        }, {
            "sClass" : "alignLeft",
            "sTitle" : "EST",
            "sWidth" : "100px"
        }, {
            "bVisible" : false
        }, {
            "sClass" : "alignLeft",
            "sTitle" : "ACT",
            "sWidth" : "100px"
        }, {
            "bVisible" : false
        }, {
            "sClass" : "alignCenter Editable",
            "sTitle" : "BAG",
            "sWidth" : "100px"
        }, {
            "sClass" : "alignLeft",
            "sTitle" : "REM"
        }, {
            "bVisible" : false
        }, {
            "sTitle" : "&nbsp;",
            "sWidth" : "10px",
            "bSortable" : false,
            "sClass" : "Edit"
        }, {
            "sTitle" : "&nbsp;",
            "sWidth" : "10px",
            "bSortable" : false,
            "sClass" : "Delete"
        }]
    });
    $('#wdw1000_tbl div.Edit').button ({ icons : {primary : 'ui-icon-pencil'},text : false,label : 'Edit'});
    $('#wdw1000_tbl div.Delete').button ({ icons : {primary : 'ui-icon-pencil'},text : false,label : 'ui-icon-trash'});

I approached a similar performance problem by using mRender and fnRowCallback , there I separated the display content from the sorting content and returned an empty content for the display in the mRender function. 我通过使用mRenderfnRowCallback来解决类似的性能问题,在那里我将显示内容与排序内容分开,并在mRender函数中为显示返回空内容。 This reduced the initialization time dramatically. 这大大减少了初始化时间。

fnRowCallback is called whenever a row is made visible, so here I created my more "complex" markup. 每当使行可见时,都会调用fnRowCallback ,因此在这里我创建了更多的“复杂”标记。 In your example the buttons, in my case I had 2000 rows and some links inside the table that took 15 seconds to display. 在您的示例按钮中,以我为例,该表中有2000行和一些链接,这些链接需要15秒才能显示。 After applying my fix it was reduced to less than one second. 应用我的修复程序后,它减少到不到一秒钟。 If you are interested in some more detailed code examples just check out my blog post 如果您对一些更详细的代码示例感兴趣,请查看我的博客文章。

You can insert these buttons only when a row catches a mouseover event, and remove them on mouseout? 您只能在一行捕获到鼠标悬停事件时才插入这些按钮,并在鼠标悬停时将其删除吗? Then you can also probably reuse the DOM elements :) 然后,您还可以重用DOM元素:)

my 2 cents, 我的2美分

Aurelien 奥雷利安

Have you considered using the datatables editor that has this functionality built in? 您是否考虑过使用内置此功能的数据表编辑器?

I used the datatables editor for a project that did exactly what you are looking for (the rows were inventory, and the client wanted to be able to add/delete) 我将datatables编辑器用于一个项目,该项目完全符合您的期望(行是库存,并且客户希望能够添加/删除)

http://editor.datatables.net/ http://editor.datatables.net/

And an example: http://editor.datatables.net/release/DataTables/extras/Editor/examples/inlineControls.html 还有一个示例: http : //editor.datatables.net/release/DataTables/extras/Editor/examples/inlineControls.html

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

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