在 bootstraptable 中向上或向下移动行
Move row up or down in bootstraptable
我在项目中使用 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')
但它不起作用...
有人移行成功了吗?
这里有一些东西:
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)});
}
}
我在项目中使用 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')
但它不起作用...
有人移行成功了吗?
这里有一些东西:
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)});
}
}