Browse Source

Merge pull request #7432 from wenzhixin/feature/7390

Feature/7390
文翼 1 year ago
parent
commit
0ac837b403
3 changed files with 16 additions and 1 deletions
  1. 9 0
      site/docs/api/methods.md
  2. 6 0
      src/bootstrap-table.js
  3. 1 1
      src/constants/index.js

+ 9 - 0
site/docs/api/methods.md

@@ -522,6 +522,15 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
 - **Example:** [Sort By](https://examples.bootstrap-table.com/#methods/sort-by.html)
 
+## sortReset
+
+- **Parameter:** `undefined`
+
+- **Detail:**
+
+  Resets sort state of the table regardless of whether caused by the user or programmatically.
+
+- **Example:** [Sort reset](https://examples.bootstrap-table.com/#methods/sort-reset.html)
 
 ## toggleDetailView
 

+ 6 - 0
src/bootstrap-table.js

@@ -534,6 +534,12 @@ class BootstrapTable {
     }
   }
 
+  sortReset () {
+    this.options.sortName = undefined
+    this.options.sortOrder = undefined
+    this._sort()
+  }
+
   sortBy (params) {
     this.options.sortName = params.field
     this.options.sortOrder = params.hasOwnProperty('sortOrder') ? params.sortOrder : 'asc'

+ 1 - 1
src/constants/index.js

@@ -483,7 +483,7 @@ const METHODS = [
   'togglePagination', 'toggleFullscreen', 'toggleView',
   'resetSearch',
   'filterBy',
-  'sortBy',
+  'sortBy', 'sortReset',
   'scrollTo', 'getScrollPosition',
   'selectPage', 'prevPage', 'nextPage',
   'toggleDetailView',