[英]jQuery sortable move row to top on button click
I'm using jQuery Sortable
to drag and drop reorder table rows successfully. 我正在使用
jQuery Sortable
成功拖放重新排序表行。 I'm also trying to add a move to top row
button on each row. 我也试图在每一行上添加一个
move to top row
按钮。 I'm able to get the row to move to top, but the jQuery sortable that creates a serialized array order for POST
does not get updated when the row is moved. 我能够将行移到顶部,但是当移动行时,为
POST
创建序列化数组顺序的jQuery sortable不会更新。 Here is what I have: 这是我有的:
HTML HTML
<table>
<thead>
<tr>
<th> </th>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody id="order">
<tr class='position' id='{$record['IapId']}-{$order}'>
<td><a id='move-to-top' href='#' class='btn btn-info btn-xs' role='button'><i class='icon-arrow-up'></i></a></td>
<td>21</td>
<td>Red Car</td>
</tr>
</tbody>
</table>
jQUERY jQuery的
<script type="text/javascript">
$(document).ready(function(){
$('tbody#order').sortable({
axis: 'y',
stop: function (event, ui) {
var data = $(this).sortable('serialize');
$('#output').val(data);
}
});
$('a#move-to-top').click(function() {
row = $(this).closest('tr');
$(this).closest('tbody#order').prepend(row);
});
});
</script>
SERIALIZED OUTPUT FOR POST POST的SERIALIZED OUTPUT
<input type="hidden" name="cars" id="output" />
Suggestions on how to get the TR
that is prepended to top of <tbody>
to also reflect in the serialized output from jQuery Sortable
? 关于如何获得前置于
<tbody>
之上的TR
建议也反映在jQuery Sortable
的序列化输出中?
Try out this.. 试试这个......
var data = $(this).sortable('toArray');
Or poke around here for an answer as well: https://api.jqueryui.com/sortable/#method-serialize 或者在这里寻找答案: https : //api.jqueryui.com/sortable/#method-serialize
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.