【发布时间】:2012-01-06 10:06:36
【问题描述】:
我有一个具有固定行布局的表格。每行都有唯一的标识符。当从数据库返回数据时,该表中的行具有不同的顺序。返回的数据与固定布局中存在的索引相同,因此我可以在固定表中找到匹配的行。我需要移动固定表格布局中的行以匹配数据中的行顺序。
表格布局:
<table>
<tr id="a1"><td>Some Value1</td></tr>
<tr id="a2"><td>Some Value2</td></tr>
<tr id="a3"><td>Some Value3</td></tr>
<tr id="a4"><td>Some Value4</td></tr>
<tr id="a5"><td>Some Value5</td></tr>
</table>
所以如果数据库中的订单是 a3,a4,a5,我需要表格看起来像这样。
<table>
<tr id="a3"><td>Some Value1</td></tr>
<tr id="a4"><td>Some Value2</td></tr>
<tr id="a5"><td>Some Value3</td></tr>
<tr id="a1"><td>Some Value4</td></tr>
<tr id="a2"><td>Some Value5</td></tr>
</table>
是否可以按行索引移动行,或者如果我克隆该行,将其移动到特定的行索引,然后使用类似的方法删除旧行/位置。
var clonedRow = $("#tbl_lp_Forms > tbody > tr[class=" + myformurl + "] ").clone(true);
$('#tbl_lp_Forms tr:first').before(clonedRow);
希望你能帮忙!
【问题讨论】:
标签: jquery html-table move tablerow