拖动表行时,Jquery可排序错误的位置

时间:2016-10-17 14:03:24

标签: jquery

我正在使用Jquery Sortable来拖动表格行

在Stop回调函数中,我正在进行ajax调用以更新订单状态

我面临的问题是,有时我在拖放时会得到错误的位置ID。

$("#languages tbody").sortable(
{
    revert: 'invalid',
    refreshPositions: true,
    tolerance: 'pointer',
    helper: 'clone',
    start: function(e, ui)
    {
        $(this).attr('data-previndex', ui.item.index());
    },
    stop: function(e, ui)
    {
        if (!ui.sender)
        {
            var newIndex = ui.item.index() + 1;
            var oldIndex = parseInt($(this).attr('data-previndex')) + 1;
            var pac_id = ui.item.attr('pacid');
            var inputjson = {
                'pac_id': pac_id,
                'old_position': oldIndex,
                'new_position': newIndex
            };
            var reqested_data = JSON.stringify(inputjson);
            console.log('JSON Request' + reqested_data);
            $(this).removeAttr('data-previndex');
            $.ajax(
            {
                // ajax call here 
            });
        }
    }
});

http://jsfiddle.net/PP2ba/23/

能告诉我如何解决这个问题。

0 个答案:

没有答案
相关问题