【问题标题】:HTML table with rowspan reorder item drag and drop issue具有行跨度重新排序项目拖放问题的 HTML 表
【发布时间】:2015-08-11 21:36:04
【问题描述】:

我的html代码是

<table border='1px' id='sort'>
    <thead>
        <tr>
            <th>SL</th>
            <th>Sub Group</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td rowspan='3'>1</td>
            <td rowspan='3'>Fruit</td>
            <td>Mango</td>
        </tr>
        <tr>
            <td>Orange</td>
        </tr>
        <tr>
            <td>pineapple</td>
        </tr>
        <tr>
            <td rowspan='2'>2</td>
            <td rowspan='2'>Flower</td>
            <td>Rose</td>
        </tr>
        <tr>
            <td>sunflower</td>
        </tr>
    </tbody>
</table>

和js

var fixHelperModified = function(e, tr) {
    var $originals = tr.children();
    var $helper = tr.clone();
    $helper.children().each(function(index) {
        $(this).width($originals.eq(index).width())
    });
    return $helper;
},
    updateIndex = function(e, ui) {
        $('td.index', ui.item.parent()).each(function (i) {
            $(this).html(i + 1);
        });
    };

$("#sort tbody").sortable({
    helper: fixHelperModified,
    stop: updateIndex
}).disableSelection();

我只想重新排序水果芒果、橙子或向日葵等子组,而不是表中的主要组。 工作小提琴是http://jsfiddle.net/p6c814o6/。如何解决这个问题。谢谢。

【问题讨论】:

  • 你不能只创建 1 个表格单元格,然后在该单元格中创建一个可排序的列表吗?
  • 这是个好主意。但是当我添加一个像type of mango 这样的新子组时,它会更难显示,并且rowspan 值实际上来自数据库。这就是为什么我想保留这个。谢谢。

标签: javascript jquery


【解决方案1】:

试试这个:

我已经更新了你的小提琴JsFiddle。根据您的代码,您的 html 是错误的。您必须检查新的 html。 而不是使用行跨度,您必须使用嵌套表来实现它。

<table border='1px' id='sort'>
    <thead>
        <tr>
            <th>SL</th>
            <th>Sub Group</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td >1</td>
            <td >Fruit</td>
            <td><table>
                <tr>
            <td>Mango</td>
        </tr>
                <tr>
            <td>Orange</td>
        </tr>
        <tr>
            <td>pineapple</td>
        </tr></td>
        </tr>
        </table>
        <tr>
            <td >2</td>
            <td >Flower</td>
            <td><table>
                <tr>
                    <td>
                Rose
                    </td>
                </tr>
            <tr>
            <td>sunflower</td>
        </tr>
                </table>
            </td>

    </tbody>
</table>

查看更新的小提琴。如果这是你需要的。 希望这有助于JsFiddleUpdated

【讨论】:

  • 谢谢,但我只想重新排序嵌套表而不是主表。这是我的要求。
  • 谢谢。最后一个问题,如何使用td 获取嵌套表index,以便我可以通过ajax 请求在数据库中更新它。我试过$( "#sort tbody tr td &gt; table tbody" ).sortable( "serialize", { key: 'td' } ); 不起作用
  • 查看此链接。这可能会帮助你。 stackoverflow.com/questions/2979643/jquery-ui-sortable-position.
猜你喜欢
  • 2012-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-20
  • 2014-01-18
  • 1970-01-01
相关资源
最近更新 更多