Browse Source

Merge pull request #6531 from marceloverdijk/onToggleCustomView

Introduces a new `onToggleCustomView` event
Dustin Utecht 3 years ago
parent
commit
aaec5a1d1c

+ 31 - 5
site/docs/extensions/custom-view.md

@@ -76,13 +76,39 @@ This extension adds the ability to create a custom view to display the data.
 
 
 ## Events
 ## Events
 
 
-### onCustomViewPreBody(custom-view-pre-body.bs.table)
+### onCustomViewPreBody
 
 
-* Fires before the custom view was rendered.
+- **jQuery Event:** `custom-view-pre-body.bs.table`
 
 
-### onCustomViewPostBody(custom-view-post-body.bs.table)
+- **Parameter:** `undefined`
 
 
-* Fires after the custom view was rendered.
+- **Detail:**
+
+  It fires before the custom view was rendered.
+
+### onCustomViewPostBody
+
+- **jQuery Event:** `custom-view-post-body.bs.table`
+
+- **Parameter:** `undefined`
+
+- **Detail:**
+
+  It fires after the custom view was rendered.
+
+### onToggleCustomView
+
+* It fires when the custom view is toggled.
+
+- **jQuery Event:** `toggle-custom-view.bs.table`
+
+- **Parameter:** `state`
+
+- **Detail:**
+
+  It fires when the custom view is toggled:
+
+  * `state`: the new custom view state (`true`-> Custom view is enabled, `false` -> Custom view is disabled )
 
 
 ## Localizations
 ## Localizations
 
 
@@ -90,4 +116,4 @@ This extension adds the ability to create a custom view to display the data.
 
 
 - **type:** `Function`
 - **type:** `Function`
 
 
-- **Default:** `function () { return "Toggle custom view" }`
+- **Default:** `function () { return "Toggle custom view" }`

+ 6 - 1
src/extensions/custom-view/bootstrap-table-custom-view.js

@@ -29,6 +29,9 @@ $.extend($.fn.bootstrapTable.defaults, {
   },
   },
   onCustomViewPreBody () {
   onCustomViewPreBody () {
     return false
     return false
+  },
+  onToggleCustomView () {
+    return false
   }
   }
 })
 })
 
 
@@ -43,7 +46,8 @@ $.fn.bootstrapTable.methods.push('toggleCustomView')
 
 
 $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
 $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
   'custom-view-post-body.bs.table': 'onCustomViewPostBody',
   'custom-view-post-body.bs.table': 'onCustomViewPostBody',
-  'custom-view-pre-body.bs.table': 'onCustomViewPreBody'
+  'custom-view-pre-body.bs.table': 'onCustomViewPreBody',
+  'toggle-custom-view.bs.table': 'onToggleCustomView'
 })
 })
 
 
 $.BootstrapTable = class extends $.BootstrapTable {
 $.BootstrapTable = class extends $.BootstrapTable {
@@ -105,5 +109,6 @@ $.BootstrapTable = class extends $.BootstrapTable {
   toggleCustomView () {
   toggleCustomView () {
     this.customViewDefaultView = !this.customViewDefaultView
     this.customViewDefaultView = !this.customViewDefaultView
     this.initBody()
     this.initBody()
+    this.trigger('toggle-custom-view', this.customViewDefaultView)
   }
   }
 }
 }