2015-04-07 33 views
0

我試圖用行索引使用行時(未更新)。每一個()。remove()方法

table.rows('.selected').every(function(){ 
    this.remove() 
}); 

刪除jQuery的數據表中選擇行,但我發現,當一列被刪除,行索引沒有更新,所以這會導致混亂。那麼是否有一種方便的方法來從表格中刪除選定的行,或者我應該手動更新行索引?

我想申請在每行一些其他的操作,除了去除,所以我不希望使用

table.rows('.selected').remove(); 
+0

也許我有知識的缺乏,有一個叫做'every'功能,它不應該是'each'? – renakre

+0

@erkaner [every](https://datatables.net/reference/api/rows().every())可能在v1.10.6中引入。 – lil

回答

-1

當我刪除行的索引號被更新。試試代碼打擊。

單擊一行。它會提醒它的索引然後刪除它自己。嘗試點擊後面的行,該行現在應該與刪除的行具有相同的索引。

$('table tr').click(function(){ 
 
    alert(this.rowIndex); 
 
    $(this).remove(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<table> 
 
    <tr> 
 
    <td>Click to remove</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Click to remove</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Click to remove</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Click to remove</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Click to remove</td> 
 
    </tr> 
 
</table>