Browse Source

Fix rows reorder when pagination is applied.

When the pagination is activated and the rows are reordered on pages other than the first one, the order was not taking into account the page number and the page size. This commit changes the index at which the row needs to be inserted by accounting for the page size and page number.
Sheikh Abdul Manan 2 years ago
parent
commit
5e7effe95d
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/extensions/reorder-rows/bootstrap-table-reorder-rows.js

+ 3 - 1
src/extensions/reorder-rows/bootstrap-table-reorder-rows.js

@@ -97,6 +97,8 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
   onDrop (table) {
     this.$draggingTd.css('cursor', '')
+    const pageNum = $(table).bootstrapTable('getOptions').pageNumber;
+    const pageSize = $(table).bootstrapTable('getOptions').pageSize;
     const newData = []
 
     for (let i = 0; i < table.tBodies[0].rows.length; i++) {
@@ -109,7 +111,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
     const draggingRow = this.data[this.draggingIndex]
     const droppedIndex = newData.indexOf(this.data[this.draggingIndex])
     const droppedRow = this.data[droppedIndex]
-    const index = this.options.data.indexOf(this.data[droppedIndex])
+    const index = ((pageNum - 1)*pageSize) + this.options.data.indexOf(this.data[droppedIndex])
 
     this.options.data.splice(this.options.data.indexOf(draggingRow), 1)
     this.options.data.splice(index, 0, draggingRow)