jQuery DataTables rowReorder issue

前端 未结 4 486
终归单人心
终归单人心 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:02

    this is code to destroy and reset datatable

    if ($.fn.DataTable.isDataTable("#categoryListDataTable"))
    {
        $("#categoryListDataTable").dataTable().fnDestroy();
    }
    
    var table = $('#categoryListDataTable').DataTable( {
        rowReorder: true,
    } );
    
    
    table.on( 'row-reorder', function ( e, diff, edit ) {
        var res = '';
        for ( var i=0, ien=diff.length ; i

    made this another function due to getting values and run ajax to save at server side

    function getVal(res)
    {
        var atmp = res.split('=');
        var newId = '';
        var newArr = [];
        for(var i=0,j=atmp.length;i';
        $.ajax({
            data:{new_:newArr},
            url:urlStr,
            cache:false,
            method:'POST',
            success:function(data){
                console.log(data);
            },
            error:function(error){
                console.log(error);
            }
        });
    }
    

提交回复
热议问题