在两个数据表之间移动行 [英] move rows between two datatables

查看:87
本文介绍了在两个数据表之间移动行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这里的东西,我有两个数据表并排,并且我添加从表A到表B的项目(行)。



'之前'datatable我正在使用附加功能:

  function add(num)
{
...
$(#myDiv1 tr#p+ num).appendTo(#myDiv2);
...
}

当然这不适用于数据表因为没有更新表,我似乎无法使用数据表函数工作,我的代码如下所示,但根本不起作用:

  function add()
{
...
stockTable = $('#stocktable')dataTable();
catalogTable = $('#catalogtable')。dataTable();
var trdata = stockTable.fnGetData($(this).closest('tr'));
stockTable.fnDeleteRow($(this).closest('tr'));
catalogtable.fnAddData(trdata);
...
}

帮助赞赏!

解决方案

目前还不清楚什么是不工作,但这里是一个工作示例:

  stockTable.on('click','tbody tr',function(){
var $ row = $(this);
var addRow = stockTable.fnGetData(this);
catalogTable.fnAddData(addRow);
stockTable.fnDeleteRow($ row.index());
});

演示 - > http://jsfiddle.net/AgB38/






更新。上面的答案是针对数据表1.9.x.以下是使用新API的dataTable 1.10.x的相同答案。

  stockTable.on ('click','tbody tr',function(){
var $ row = $(this);
var addRow = stockTable.row($ row);
catalogTable.row。 add(addRow.data())。draw();
addRow.remove()。draw();
});

演示 - > http://jsfiddle.net/4cf43tv1/


So here's the thing, I have two datatables side by side and I nedd to add items(rows) from Table A to Table B.

'Before' datatable I was doing all right using append:

function add(num)
{
      ...
      $("#myDiv1 tr#p"+num).appendTo("#myDiv2");
      ...
}

Of course this doesn't work with datatables since does not update the table, and I can't seem to get It working using datatables functions, my code goes like the following but isn't working at all:

function add()
{
       ...
       stockTable = $('#stocktable').dataTable();
       catalogTable = $('#catalogtable').dataTable();
       var trdata = stockTable.fnGetData($(this).closest('tr'));
       stockTable.fnDeleteRow($(this).closest('tr'));
       catalogtable.fnAddData(trdata);
       ...
}

Help appreciated!

解决方案

It is unclear exactly what is not working, but here is a working example :

stockTable.on('click', 'tbody tr' ,function() {
   var $row = $(this);
   var addRow = stockTable.fnGetData(this);
   catalogTable.fnAddData(addRow);
   stockTable.fnDeleteRow($row.index());
});

demo -> http://jsfiddle.net/AgB38/


Update. The above answer was targeting dataTables 1.9.x. Below is the same answer targeting dataTables 1.10.x, using the new API.

stockTable.on('click', 'tbody tr' ,function() {
    var $row = $(this);
    var addRow = stockTable.row($row);
    catalogTable.row.add(addRow.data()).draw();
    addRow.remove().draw();
});

demo -> http://jsfiddle.net/4cf43tv1/

这篇关于在两个数据表之间移动行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆