浏览代码

[Addrbar] Added a new option for custom parameters. (#7350)

* Added a new option `addrCustomParams` which allows to add custom get params

* Update site/docs/extensions/addrbar.md

Co-authored-by: 文翼 <wenzhixin2010@gmail.com>

* Update site/docs/extensions/addrbar.md

Co-authored-by: 文翼 <wenzhixin2010@gmail.com>

* Added missing empty line

---------

Co-authored-by: 文翼 <wenzhixin2010@gmail.com>
Dustin Utecht 1 年之前
父节点
当前提交
1a1a981128
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 13 0
      site/docs/extensions/addrbar.md
  2. 10 1
      src/extensions/addrbar/bootstrap-table-addrbar.js

+ 13 - 0
site/docs/extensions/addrbar.md

@@ -32,6 +32,19 @@ Every time when changing page, sorting and searching operation, it will change t
 
 - **Default:** `false`
 
+### addrCustomParams
+
+- **Attribute:** `data-addr-custom-params`
+
+- **Type:** `Function|Object`
+
+- **Detail:**
+
+  Define an object in which key and value pairs will be added as custom/additional get parameters to the URL, for example, custom filters.
+  The `key` is the GET parameter name, and the `value` is the value of the GET parameter.
+
+- **Default:** `{}`
+
 ### addrPrefix
 
 - **Attribute:** `data-addr-prefix`

+ 10 - 1
src/extensions/addrbar/bootstrap-table-addrbar.js

@@ -6,9 +6,12 @@
  * @update: zhixin wen <wenzhixin2010@gmail.com>
  */
 
+const Utils = $.fn.bootstrapTable.utils
+
 Object.assign($.fn.bootstrapTable.defaults, {
   addrbar: false,
-  addrPrefix: ''
+  addrPrefix: '',
+  addrCustomParams: {}
 })
 
 $.BootstrapTable = class extends $.BootstrapTable {
@@ -89,6 +92,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
       }
     }
 
+    const customParams = Utils.calculateObjectValue(this.options, this.options.addrCustomParams, [], {})
+
+    for (const [key, value] of Object.entries(customParams)) {
+      this.searchParams.set(key, value)
+    }
+
     let url = `?${this.searchParams.toString()}`
 
     if (location.hash) {