2015-10-19 52 views
1

我想从表中删除多行,并且我已经使用下面的代码,但不起作用。
我使用DataTables v1.10.9从表中删除多选的行

$('#del_Btn').on('click', function() { 
    // 'table' is the instance of table object 
    table.row('.selected').remove().draw(false); 
} 

全码:

$('#del_MembersBtn').on('click', function() { 

if (confirm('Do you want to remove the selected items ?') === true) { 
    var selRows = RemoveFromGroupTable.rows({selected: true}).data().pluck(0); // return an object contains selected rows 
    var selRowsLength = selRows.length; 
    var rows = new Array(); 
    for (i = 0; i < selRowsLength; i++) { 
     rows.push(selRows[i]); 
    } 

    // remove the selected rows from table 
    RemoveFromGroupTable.rows('.selected').remove().draw(false); 
    var inputData = {}; 
    inputData.selectdRows = rows; 
    inputData.submit = Math.floor(Math.random() * 10) + 1; 
    $.post(myProp.base_url + 'directory/class/method', inputData, function (outputData) { 
     if (outputData.submit == outputData.submit) { 
      tips(); 
     } 
    }, 'json'); 
} 

} });

我能做些什么来移除多个选定的行?

回答

0

SOLUTION

使用rows选择如下所示

$('#del_Btn').on('click', function() { 
    table.rows('.selected').remove().draw(false); 
} 

如果按钮位于表里面从表中的多个行,这将是使用委托事件处理程序的必要性如下:

$('#example').on('click', '#del_btn', function() { 
    table.rows('.selected').remove().draw(false); 
} 

其中example是你的表ID。

DEMO

this jsFiddle代码和演示。

+0

谢谢,但不幸的是,它不起作用,它只是从选定的项目中删除颜色。我已更新我的问题,请参阅我的完整代码。 –

+0

@LionKing,添加了[demo](https://jsfiddle.net/9v0wofbh/)来表明我的解决方案有效。 –