【问题标题】:Drag and Drop between 2 tables using Jquery sortable with rowspan and colspan使用带有rowspan和colspan的Jquery可在2个表之间拖放
【发布时间】:2014-05-18 09:53:59
【问题描述】:

我正在尝试在另一个表中移动行跨度 > 2 或 colspan > 2 的行。

问题是当我将它放入一个单元格时,它会在该单元格中创建一个新的 tr。

我正在考虑在拖放对象时将父行跨度或列跨度设置为与子级相同。

http://jsbin.com/jumalofe/1/watch?html,js,output

假设“AIBD”应该是从 08-00 到 12:00 。我该怎么做??

【问题讨论】:

  • 你需要它是<td>AIBD</td>而不是<td><tr><td>AIBD</td></tr></td>吗?
  • 我希望能够在同一个表格单元格中放置更多内容。最后应该是:fsc.ugal.ro/nou/files/studenti/orare/an_4_C.pdf
  • 在你提供的jsbin demo中,我可以将AIBD和SINCO放在同一个单元格中。抱歉,我不明白你的问题。
  • Its ok. I会更具体。 AIBD 在第一个表中有 colspan 2。当我将它移到第二个表中时,它将是: AIBD 我想要 ....

标签: javascript jquery jquery-ui drag-and-drop jquery-ui-sortable


【解决方案1】:

这就是你要做的。我们将使用 sortable 的receive 事件:

接收(事件,用户界面)

当连接的可排序列表中的项目时触发此事件 已被放入另一个列表。后者是事件目标。

receive:function(event, ui) {

      //we check if the <td> has rowspan property
     if(typeof ui.item.attr('rowspan') !== 'undefined' && ui.item.attr('rowspan') !== false){

        //if it does, we store it in a variable
        rowspan = ui.item.attr('rowspan');

        //the element we are dropping to, we set the rowspan there
        //(content is automatically inserted)
        $(this).attr('rowspan',rowspan);

        //we set the rowspan of sender element to 0, this is the case where
        //you are re-dragging the 'AIDB' to some other row, if you do, 
        //we want the previous row to be same as before, free of any rowspan
        ui.sender.attr('rowspan',0);

      }

      //same case for colspan
      if(typeof ui.item.attr('colspan') !== 'undefined' && ui.item.attr('colspan') !== false){

        colspan = ui.item.attr('colspan');
        $(this).attr('colspan',colspan);
        ui.sender.attr('colspan',0);

      }
}

DEMO

【讨论】:

  • 谢谢!使用 rowspan 它可以工作,但会在下一行的末尾创建一个新单元格。使用 colspan 它不会t work. Unfortunely, im 是 js 的新手,我不知道会出现什么问题。
  • @CristianSimion 我已经修复了它以与 colspan 一起使用,但新的单元格的东西很复杂。这个想法是,如果假设你的 colspan 为 2,最后一个单元格将被删除,但如果你要在最后一个元素处删除单元格,那么这将不起作用。
猜你喜欢
  • 2014-04-13
  • 2018-11-02
  • 2018-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多