浏览代码

Merge pull request #6445 from marceloverdijk/sortResetPage2

Reset page number when sorting option `sortResetPage`
文翼 3 年之前
父节点
当前提交
94171816a3
共有 3 个文件被更改,包括 20 次插入0 次删除
  1. 1 0
      index.d.ts
  2. 14 0
      site/docs/api/table-options.md
  3. 5 0
      src/bootstrap-table.js

+ 1 - 0
index.d.ts

@@ -162,6 +162,7 @@ export interface BootstrapTableOptions {
   pageSize?: number;
   footerField?: string;
   showFullscreen?: boolean;
+  sortResetPage?: boolean;
   sortStable?: boolean;
   searchAlign?: string;
   ajax?: (params: BootstrapAjaxParams) => any;

+ 14 - 0
site/docs/api/table-options.md

@@ -1657,6 +1657,20 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Sort Reset](https://examples.bootstrap-table.com/#options/sort-reset.html)
 
+## sortResetPage
+
+- **Attribute:** `data-sort-reset-page`
+
+- **Type:** `Boolean`
+
+- **Detail:**
+
+  Set `true` to reset the page number when sorting.
+
+- **Default:** `false`
+
+- **Example:** [Sort Reset Page](https://examples.bootstrap-table.com/#options/sort-reset-page.html)
+
 ## sortStable
 
 - **Attribute:** `data-sort-stable`

+ 5 - 0
src/bootstrap-table.js

@@ -557,6 +557,11 @@ class BootstrapTable {
       return
     }
 
+    if (this.options.pagination && this.options.sortResetPage) {
+      this.options.pageNumber = 1
+      this.initPagination()
+    }
+
     this.initSort()
     this.initBody()
   }