angular-datatable column draggable out of the table

后端 未结 1 418
暗喜
暗喜 2021-01-21 10:50

Is it possible to avoid the column, not to drag out of the data-table view area, as you can make out yourself, what I am talking about from this link https://l-lin.github.io/ang

1条回答
  •  天涯浪人
    2021-01-21 11:27

    As l-lin points out, angular-datatables is a wrapper for jQuery dataTables providing directives and making sure dataTables not is conflicting with angular. To change core functionality you must still change the core.

    You can change many things in the dataTables core libraries by monkey patching. To prevent dragging of a column header outside the section of a table you can do this :

    var old_fnMouseMove = $.fn.DataTable.ColReorder.prototype._fnMouseMove;
    $.fn.DataTable.ColReorder.prototype._fnMouseMove = function(e) {
        var x = e.clientX, 
            y = e.clientY, 
            r = document.querySelector('#example thead').getBoundingClientRect(),
            within = (x>r.left && xr.top && y

    The above override ColReorders mousemove events when dragging is going on. If the mouse is outside the element it simply just dont pass the event to the original function - by that dragging a column outside is effectively prevented.

    angular-datatables demo -> http://plnkr.co/edit/uPv8FoUrJkQWnEaE2AQY?p=preview

    pure jQuery dataTables demo -> http://jsfiddle.net/0boznoh7/

    0 讨论(0)
提交回复
热议问题