Browse Source

Merge pull request #5175 from wenzhixin/feature/add-more-context-to-events

Feature/add more context to events
Dustin Utecht 5 years ago
parent
commit
66a7fb6547
2 changed files with 8 additions and 4 deletions
  1. 4 0
      site/docs/api/events.md
  2. 4 4
      src/bootstrap-table.js

+ 4 - 0
site/docs/api/events.md

@@ -9,12 +9,16 @@ toc: true
 To use event syntax:
 
 {% highlight html %}
+// Here you can expect to have as last parameter the boostrap-table object
+
 $('#table').bootstrapTable({
   onEventName: function (arg1, arg2, ...) {
     // ...
   }
 })
 
+// Here you can expect to have in the 'e' variable the sender property which is the boostrap-table object
+
 $('#table').on('event-name.bs.table', function (e, arg1, arg2, ...) {
   // ...
 })

+ 4 - 4
src/bootstrap-table.js

@@ -1862,11 +1862,11 @@ class BootstrapTable {
 
   trigger (_name, ...args) {
     const name = `${_name}.bs.table`
-    this.options[BootstrapTable.EVENTS[name]](...args)
-    this.$el.trigger($.Event(name), args)
+    this.options[BootstrapTable.EVENTS[name]](...[...args, this])
+    this.$el.trigger($.Event(name, { sender: this }), args)
 
-    this.options.onAll(name, args)
-    this.$el.trigger($.Event('all.bs.table'), [name, args])
+    this.options.onAll(name, ...[...args, this])
+    this.$el.trigger($.Event('all.bs.table', { sender: this }), [name, args])
   }
 
   resetHeader () {