Move a line up or down in a boot file

I am using Bootstrap-Table in a project and I would like to move rows up or down.

I have these 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 the lines on the screen, but this does not work as well as the row index has not changed ...

So, I tried changing the line .data('index') , but it does not work ...

Has anyone succeeded in moving the line?

+7
javascript jquery twitter-bootstrap bootstrap-table
source share
1 answer

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)}); } } 
+5
source share

All Articles