[英]How to pass clicked/selected row data from one table to another table that are placed side by side
I have two tables that are placed side by side and i would to append selected row on the first table to the second tab 我有两个并排放置的表,我会将第一个表上的选定行附加到第二个选项卡上
i managed to get the data from a selected row and convert it to an array. 我设法从选定的行中获取数据并将其转换为数组。 I tried using the v-bind tag to bind the data values in the second table and its not working
我尝试使用v-bind标记绑定第二个表中的数据值,但它不起作用
I expect to click a row in a table and that row is added to another table that is just placed on the side of the other table 我希望单击一个表中的一行,并将该行添加到另一个表中,该表仅位于另一个表的侧面
What I understood from you question is that you are looking for a jquery code that makes the rows from the two tables to move from one table to the other whenever the user clicks on a row in any of the tables. 我从您的问题中了解到的是,您正在寻找一种jquery代码,每当用户单击任何表中的一行时,该代码都会使两个表中的行从一个表移动到另一个表。 for example if you click on a row in first table, it moves to the second table and if you click on a row in second table, it moves to the first table.
例如,如果您单击第一张表中的一行,它将移至第二张表;如果您单击第二张表中的一行,它将移至第一张表。 if it is so, then the jquery code could be:
如果是这样,那么jQuery代码可能是:
// identify the two tables with IDs for easier access
var tbl1=$('#table_1_id'), tbl2=$('#table_2_id');
// use tbody selector to make sure that you don't bind this event to table heading rows
$('#table_1_id,#table_2_id').find('tbody tr').on('click', moveRow);
function moveRow() {
// find on which table this row is
var row = $(this);
var table_current = row.closest('table');
// If current table ID equals to first table ID then it means we are in first table
if (table_current.prop('id')==tbl1.prop('id')) {
// Then we move the row to second table
tbl2.find('tbody').append(row);
} else {
// The row was in second table so we move it to first table
tbl1.find('tbody').append(row);
}
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.