【问题标题】:Move row up or down in bootstraptable在引导表中向上或向下移动行
【发布时间】:2015-07-16 04:43:56
【问题描述】:

我在一个项目中使用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());
},
}

它在屏幕上移动行,但由于行索引没有改变,所以效果并不好......

所以我尝试更改行 .data('index') 但它不起作用...

有人成功移动行吗?

【问题讨论】:

  • 你能提供一个小提琴吗???
  • 这里是小提琴:jsfiddle.net/dfpo899p 如果您通过单击 + 或 - 移动行并按下按钮,您可以看到数据保持不变,如果我通过示例添加删除按钮会导致问题.. .

标签: javascript jquery twitter-bootstrap bootstrap-table


【解决方案1】:

这里有一些东西:

小提琴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)});
        }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多