我使用这里给出的代码使用jquery在gridview中上下移动行,这非常有效,但是如何实现将行移动到表中的第一个位置或最后一个位置?
我有一个具有固定行布局的表.每行都有唯一的标识符.从数据库返回数据时,它对该表中的行具有不同的顺序.返回的数据与固定布局中存在的索引相同,因此我可以在固定表中找到匹配的行.我需要移动固定表布局中的行以匹配数据中的行顺序.
表格布局:
<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>
Run Code Online (Sandbox Code Playgroud)
因此,如果数据库中的订单是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>
Run Code Online (Sandbox Code Playgroud)
是否可以逐行移动索引,或者如果我克隆行,将其移动到特定的行索引,然后用这样的东西删除旧的行/位置.
var clonedRow = $("#tbl_lp_Forms > tbody > tr[class=" + myformurl + "] ").clone(true);
$('#tbl_lp_Forms tr:first').before(clonedRow);
Run Code Online (Sandbox Code Playgroud)
希望你能帮忙!