简体   繁体   English

如何将单击/选定的行数据从一个表传递到另一个并排放置的表

[英]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.

相关问题 如何从客户端添加行的表中获取数据? - How to get data from table which add row at client side? 我如何仅使用客户端将数据从一个视图传递到另一个视图? - how can i pass the data from one view to another using client side only? 如何通过Vue将数据从表组件传递到另一个表组件,并使用编辑按钮传递表中的每一行 - how pass data from a table component in vue to another table component passing each row in the table with an edit button 如何通过JSON将表数据从HTML前端和HTML前端传递到Django中的服务器端? - How to pass a table data from and HTML front end to the server side in Django through JSON? 如何以角度 9 将表数据从一个组件推送/传递到另一个组件? - How to push/pass table data from one component to another in angular 9? 在yii2中单击按钮时,如何将数据从一个表保存到另一表? - How to save the data from one table to another table when button is clicked in yii2? 如何在单个对象中并排获得表格行? - How to get side by side table row in single objects? 如何将表记录标识符传递给客户端 - How to pass table record identifier to client side 单击一行时,如何将“选定”类添加到表的一行? - How can I add a “selected” class to just one row of a table when a row is clicked? 如何将选定表行中的 ID 传递到我的 AJAX function 以获取数据 - How can I pass an ID from selected table row to my AJAX function that fetching data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM