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 ?
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)});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With