2015-10-19 83 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/)來表明我的解決方案有效。 –