数据表移动行按钮

Datatable move rows button

本文关键字:按钮 移动 数据表      更新时间:2023-09-26

我有两个数据表,并且具有将行从一个移动到另一个的函数,它按原样完美运行,但我想触发操作不是通过单击行而是通过单击按钮,尝试更改它但不起作用。

...
stockTable.on('click', 'tr' ,function() {     //'#toggle' selector instead 'tr'
    var $row = $(this);                       // $(this).closest('tr'); instead $(this);
    var addRow = stockTable.fnGetData(this);  //$(this).closest('tr'); instead 
    catalogTable.fnAddData(addRow);
    stockTable.fnDeleteRow($row.index());
});
...
<td><button class="toggle">C</button></td>
....

对不起,如果这个问题可能看起来很愚蠢,但我不喜欢javascript。提前谢谢。

tr替换为.toggle,它应该可以工作。您正在尝试使用 ID #选择器,您需要一个类.选择器。

stockTable.on('click', '.toggle' ,function() {

然后,您必须将其重新分配给最接近的tr

var $row = $(this).closest("tr");