jQuery DataTables rowReorder issue

前端 未结 4 507
终归单人心
终归单人心 2021-01-03 05:05

I am using DataTables along with the rowReorder plugin against a static table (non AJAX) - everything initialises fine but when I drag a row, whilst it moves within the tabl

4条回答
  •  长发绾君心
    2021-01-03 06:04

    This is getting a bit aged, but I had to work through it and thought I'd share what I did. My requirements had this a table with sortable rows, but ordering by header click was not a requirement and made the UI a bit confusing.

    The HTML is a fairly standard table.

    HTML

    The javascript is also fairly straight forward. The major difference is the addition of a draw event handler. This iterates the header fields and strips the class tag, and also removes the click handler. This code was called from a page onload hander.

    JAVASCRIPT

    function removeSorting() {
        $.each($('#maskEditTable').find('thead > tr > th'), function (i, header) {
            $(header).attr('class', null);
            $(header).off('click');
        });
    }
    function() init(){
        var tab = $('#maskEditTable')
            .DataTable({
            paging: false,
            info: false,
            searching: false,
            rowReorder: {
                selector: 'tr',
                update: true
            },
            order: [[0, "asc"]],
            columnDefs: [
                {
                    targets: 0,
                    visible: true
                }
            ]
            });
        tab.on('draw.dt', removeSorting);
        removeSorting();
    }
    

    The results are exactly what I was expecting and there is no visible effects on the redraw in any of my tests.

    GL!

    提交回复
    热议问题
    Position Valid Characters Is Literal Character
    0
    1
    2
    3
    4