可拖动连接到可排序

Draggable connected to sortable

本文关键字:排序 连接 拖动      更新时间:2023-09-26

我希望能够将项目从一个inffragistics DataGrid拖到另一个,而Destination网格中的项目也是可排序的。

不幸的是,我不能使用jsfiddle,因为我不能使用那里的inffragistics控件。

$("[id*=sourceGrid] [id*=dataTbl] tbody tr").draggable({
   helper: "clone",
   revert: "invalid",
   connectToSortable: '[id*=destination]'                   
});
$("[id*=destinationGrid]").sortable({
   cursor: 'move',
   helper: fixHelperModified,    
   revert: true,
   items: "[id*=container] [id*=dataTbl] tbody tr:not(.placeholder)",                
   receive: function (event, ui) {                    
      var grid = $IG.WebDataGrid.find("destinationGrid");                   
      $sentence = $(ui.item).find("td").eq(0).html();
      var row = new Array(Math.floor((Math.random() * 100) + 1), $sentence, $order);
      grid.get_rows().add(row);                  
  }
});

问题是:当我将项目从sourceGrid拖放到destinationGrid中时,我不希望将可拖拽元素放置到新的Grid中—我只想使用接收函数在网格中创建具有可拖拽元素值的新行。现在,我得到了两者——新创建的网格和掉落的物品。我怎样才能避免呢?

您可以在beforeStop事件中捕获复制的项。

var newItem;
$(".list").sortable({
  connectWith: ".list",
  beforeStop: function (event, ui) { 
      newItem = ui.item;
  },
  receive: function(event,ui) {
      $(newItem).doSomething();
  }
});​

参考和信用这个答案:https://stackoverflow.com/a/5864644/3523694