在bootstraptable中向上或向下移动行

Ama*_*ine 7 javascript jquery twitter-bootstrap bootstrap-table

我正在项目中使用Bootstrap-Table,我想向上或向下移动行.

我有这些动作事件:

window.actionEvents = {
'click .up': function (e, value, row, index) {
var thisrow = $(this).parents("tr:first"),
thisrow.prev().data('index', rowindex);
},
'click .down': function (e, value, row, index) {
var thisrow = $(this).parents("tr:first");
thisrow.insertAfter(thisrow.next());
},
}
Run Code Online (Sandbox Code Playgroud)

它在屏幕上移动行但由于行索引没有改变而无法正常工作......

所以我试图改变行,.data('index')但它不起作用......

有人成功移动了一排吗?

Pim*_*Web 5

这是一些东西:

小提琴:https://jsfiddle.net/dfpo899p/1/

Js:

window.actionEvents = {
    'click .up': function (e, value, row, index) {
        var source = JSON.stringify($('#table').bootstrapTable('getData')[index]);
        var target = JSON.stringify($('#table').bootstrapTable('getData')[index - 1]);
        $('#table').bootstrapTable('updateRow', {'index':index - 1, 'row': JSON.parse(source)});
        $('#table').bootstrapTable('updateRow', {'index':index, 'row': JSON.parse(target)});
        },
    'click .down': function (e, value, row, index) {
        var source = JSON.stringify($('#table').bootstrapTable('getData')[index]);
        var target = JSON.stringify($('#table').bootstrapTable('getData')[index + 1]);
        $('#table').bootstrapTable('updateRow', {'index':index + 1, 'row': JSON.parse(source)});
        $('#table').bootstrapTable('updateRow', {'index':index, 'row': JSON.parse(target)});
        }
}
Run Code Online (Sandbox Code Playgroud)