javascript - Move row up or down in bootstraptable - Stack Overflow

I'm using Bootstrap-Table in a project and I'd like to move rows up or down.I have these acti

I'm using Bootstrap-Table in a project and I'd like to move rows up or down.

I have these action events :

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());
},
}

It moves rows on screen but it doesn't work really well as row index haven't changed...

So I tried to change the row .data('index') but it doesn't work...

Has someone succeeded in moving row ?

I'm using Bootstrap-Table in a project and I'd like to move rows up or down.

I have these action events :

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());
},
}

It moves rows on screen but it doesn't work really well as row index haven't changed...

So I tried to change the row .data('index') but it doesn't work...

Has someone succeeded in moving row ?

Share Improve this question edited Apr 28, 2016 at 17:46 BENARD Patrick 31k16 gold badges102 silver badges108 bronze badges asked May 6, 2015 at 7:22 AmandineAmandine 1151 silver badge5 bronze badges 2
  • can you provide a fiddle??? – Guruprasad J Rao Commented May 6, 2015 at 7:33
  • Here is the fiddle : jsfiddle/dfpo899p if you move rows by clicking + or - and press button you can see that data remains the same and it causes issues if i add a delete button by example ... – Amandine Commented May 6, 2015 at 7:56
Add a ment  | 

1 Answer 1

Reset to default 6

Here is something :

Fiddle : https://jsfiddle/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)});
        }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744306585a4567743.html

相关推荐

  • javascript - Move row up or down in bootstraptable - Stack Overflow

    I'm using Bootstrap-Table in a project and I'd like to move rows up or down.I have these acti

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信