Move row up or down in bootstraptable
Asked Answered
P

1

7

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 ?

Priebe answered 6/5, 2015 at 7:22 Comment(2)
can you provide a fiddle???Merwyn
Here is the fiddle : jsfiddle.net/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 ...Priebe
L
6

Here is something :

Fiddle : 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)});
        }
}
Lindane answered 6/5, 2015 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.