Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery Sortable移动多个表行_Jquery_Jquery Ui_Jquery Ui Sortable - Fatal编程技术网

如何使用jQuery Sortable移动多个表行

如何使用jQuery Sortable移动多个表行,jquery,jquery-ui,jquery-ui-sortable,Jquery,Jquery Ui,Jquery Ui Sortable,我有一张这样的桌子: <table id="sortable"> <tr id="d1" class="mainrow"><td class="handle">O</td><td>Item 1</td></tr> <tr id="d1b"><td>&nbsp;</td><td>blah</td></tr> <tr i

我有一张这样的桌子:

<table id="sortable">
  <tr id="d1" class="mainrow"><td class="handle">O</td><td>Item 1</td></tr>
  <tr id="d1b"><td>&nbsp;</td><td>blah</td></tr>
  <tr id="d2" class="mainrow"><td class="handle">O</td><td>Item 2</td></tr>
  <tr id="d2b"><td>&nbsp;</td><td>blah</td></tr>
  <tr id="d3" class="mainrow"><td class="handle">O</td><td>Item 3</td></tr>
  <tr id="d3b"><td>&nbsp;</td><td>blah</td></tr>
  <tr id="d4" class="mainrow"><td class="handle">O</td><td>Item 4</td></tr>
  <tr id="d4b"><td>&nbsp;</td><td>blah</td></tr>
</table>
移动奇数行时,我希望将奇数行和偶数行保持在一起(偶数行没有控制柄,因此无法拾取)

我的hasChanged函数在下降发生后移动偶数行,但拖动时的视觉效果看起来是错误的;间隙显示在奇数行下,我希望它显示在偶数行下,因为在hasChanged函数完成后,间隙将结束


有人知道怎么做吗?

没关系,想出来了:

$( "#sortable tbody" ).sortable({
  stop: hasChanged,
  over: movePlaceholder,
  handle: '.handle',
  cursor: 'move'
});
我只是在movePlaceholder函数中更改占位符的位置:

function movePlaceholder(e, ui)
{
  if (ui.placeholder.prev().attr("id").length == 2)
    ui.placeholder.insertAfter(ui.placeholder.next());
}
function hasChanged(e, ui)
{
    var newPosition = ui.item.index();
    var id = ui.item.attr("id");

    // whatever you need to do goes here
}
根据要求,hasChanged功能:

function movePlaceholder(e, ui)
{
  if (ui.placeholder.prev().attr("id").length == 2)
    ui.placeholder.insertAfter(ui.placeholder.next());
}
function hasChanged(e, ui)
{
    var newPosition = ui.item.index();
    var id = ui.item.attr("id");

    // whatever you need to do goes here
}

你能添加hasChanged函数吗。