【问题标题】:jquery sortable() complete callback functionjquery sortable() 完成回调函数
【发布时间】:2015-03-06 06:06:05
【问题描述】:

我有一个包含两列的表格 - 行号和名称

表格必须可以按用户排序(使用拖放)。

这是表格的html:

<table class="table table-striped sorted_table">
        <thead>
        <tr>
            <th>#</th>
            <th>Name</th>
        </tr>
        </thead>
        <tbody id="tbody-list">
            <tr>
                <td class='td-index'>1</td>
                <td>Frank</td>
            </tr>
            <tr>
                <td class='td-index'>2</td>
                <td>Bill</td>
            </tr>
            <tr>
                <td class='td-index'>3</td>
                <td>John</td>
            </tr>
            <tr>
                <td class='td-index'>4</td>
                <td>David</td>
            </tr>
            <tr>
                <td class='td-index'>5</td>
                <td>Elisa</td>
            </tr>
            <tr>
                <td class='td-index'>6</td>
                <td>Anna</td>
            </tr>
        </tbody>
    </table>

这是用于排序的 jquery(拖放):

$('.sorted_table').sortable({
    containerSelector: 'table',
    itemPath: '> tbody',
    itemSelector: 'tr',
    placeholder: '<tr class="placeholder"/>',
    update: function( event, ui) {
        $('.td-index').each(function(index ) {
            index++;
            $(this).text(index );
        })
    }
})

我使用sorting()update 回调函数在每次排序后重新生成每行的编号 - 但它没有

我应该使用什么回调函数?

【问题讨论】:

  • 你能发一个 JSFiddle 吗?所以会很容易
  • 见 jsfiddle jsfiddle.net/45j4vm92
  • awesome answer Frebin ,您可以将其添加为答案

标签: javascript jquery jquery-ui


【解决方案1】:

尝试beforeStopstop 而不是更新

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多