Browse Source

feature/4585 (#4835)

* added an method to manually set the sort priority (to e.g. build custom interfaces)

* removed debug stuff

* removed unnecessary variable
Dustin Utecht 5 years ago
parent
commit
ec8bad2094

+ 23 - 0
site/docs/extensions/multiple-sort.md

@@ -73,6 +73,29 @@ toc: true
 
 
    Force mutltiple sort table (usable after manual data changes).
    Force mutltiple sort table (usable after manual data changes).
 
 
+
+### multiSort
+
+- **parameters:** sortPriority
+
+- **Detail:**
+
+   Set one or multiple sort priority
+
+   Example:
+   ```
+  [
+    {
+      "sortName": "forks_count",
+      "sortOrder": "desc"
+    },
+    {
+      "sortName": "stargazers_count",
+      "sortOrder": "asc"
+    }
+  ]
+  ```
+
 ## Locales
 ## Locales
 
 
 ### formatMultipleSort
 ### formatMultipleSort

+ 20 - 15
src/extensions/multiple-sort/bootstrap-table-multiple-sort.js

@@ -352,7 +352,7 @@ const showSortModal = that => {
       const fields = []
       const fields = []
       const results = []
       const results = []
 
 
-      that.options.sortPriority = $.map($rows, row => {
+      const sortPriority = $.map($rows, row => {
         const $row = $(row)
         const $row = $(row)
         const name = $row.find('.multi-sort-name').val()
         const name = $row.find('.multi-sort-name').val()
         const order = $row.find('.multi-sort-order').val()
         const order = $row.find('.multi-sort-order').val()
@@ -387,20 +387,7 @@ const showSortModal = that => {
           that.$sortModal.modal('hide')
           that.$sortModal.modal('hide')
         }
         }
 
 
-        that.options.sortName = ''
-
-        if (that.options.sidePagination === 'server') {
-          const t = that.options.queryParams
-          that.options.queryParams = params => {
-            params.multiSort = that.options.sortPriority
-            return $.fn.bootstrapTable.utils.calculateObjectValue(that.options, t, [params])
-          }
-          isSingleSort = false
-          that.initServer(that.options.silentSort)
-          return
-        }
-        that.onMultipleSort()
-
+        that.multiSort(sortPriority)
       }
       }
     })
     })
 
 
@@ -428,6 +415,7 @@ const showSortModal = that => {
 }
 }
 
 
 $.fn.bootstrapTable.methods.push('multipleSort')
 $.fn.bootstrapTable.methods.push('multipleSort')
+$.fn.bootstrapTable.methods.push('multiSort')
 
 
 $.extend($.fn.bootstrapTable.defaults, {
 $.extend($.fn.bootstrapTable.defaults, {
   showMultiSort: false,
   showMultiSort: false,
@@ -712,3 +700,20 @@ BootstrapTable.prototype.setButtonStates = function () {
     this.$sortModal.find('#delete').attr('disabled', 'disabled')
     this.$sortModal.find('#delete').attr('disabled', 'disabled')
   }
   }
 }
 }
+
+BootstrapTable.prototype.multiSort = function (sortPriority) {
+  this.options.sortPriority = sortPriority
+  this.options.sortName = ''
+
+  if (this.options.sidePagination === 'server') {
+    this.options.queryParams = params => {
+      params.multiSort = this.options.sortPriority
+      return $.fn.bootstrapTable.utils.calculateObjectValue(this.options, this.options.queryParams, [params])
+    }
+    isSingleSort = false
+    this.initServer(this.options.silentSort)
+    return
+  }
+
+  this.onMultipleSort()
+}