The internal event bus provides a way for modules and Tabulator to talk to one another and helps keep Tabulators internal logic isolated from module logic.
This section will outline all of the built in internal events in Tabulator, along with the arguments passed in those events and information about when they are dispatched.
Event Types
There are several types of event that can be dispatched. We will briefly describe each type of event here, but for a full description along with example usage cases and sample code for subscribing to each event type, please read the Building Modules Documentation
Dispatch
Dispatched events are simple send and forget notifications which do not return any values. Then can be triggered using the dispatch function.
The first argument is the name of the event, any other arguments after the event are then passed to the subscribers
this.dispatch("example-event", arg1, arg2, arg3);
Example An example usage case of this is when a row is deleted, the row dispatches a row-deleted event that lets modules know that a row has been deleted so they can carry out any needed housekeeping functions.
Chain
Chain events are used when you want to receive a response to an event, they can be used to request feedback from other modules to the result of an event.
Because any number of modules can be subscribed to an event, this isnt a simple call and response. Each subscriber is called in turn an passed the results of the last to subscriber and should return its own response combined with with that of the previous subscribers. When the last subscriber returns the result is returned to the dispatching module.
The first argument is the name of the event, The second argument is an array of arguments to be passed to the subscriber function. The third argument is the initial value to be passed into the previous value argument of the first subscriber. The fourth argument is the fallback value that will be returned if their are no subscribers to the event, this can either be a value or a callback function that is called in the event of no subscribers, that should return the fallback value,
var result =this.chain("example-event",[arg1, arg2, arg3],{},{noparams:true})
Example An example usage case of this when the data loader dispatches the data-params event to retrieve a list of ajax parameters for a request. the filter, sort and pagination modules then add their parameters to the params object and pass it back to the data loader.
Confirm
The confirm event should be used to check if modules are happy for something to proceed, if any module returns to to the event it will return true, otherwise it will return false.
The first argument is the name of the event, the second argument is an array of arguments to be passed to the subscriber function
var success =this.confirm("example-event",[arg1, arg2, arg3]);
Example The data loader dispatches a data-load confirm when it starts to load data, to allow modules to take control of the loading process and for example make an ajax request instead of the data being loaded from an array.
Inspecting Events
Understanding when events occur can be tricky to know from reading a simple list. To help you out when building your modules, Tabualtor provides a debug tool that logs internal events out to the console so you can gain practical understanding of when they are fired.
The debugEventsInternal option will create a console log for every internal event that is fired so you can gain an understanding of which events you should be subscribing to in your modules.
var table =newTabulator("#example-table",{
debugEventsInternal:true,//console log internal events});
Passing an array of event keys into this option will restrict the console logging to just the events you want to see.
var table =newTabulator("#example-table",{
debugEventsInternal:["data-loading","data-loaded"],});
Warning Tabulator fires a huge number of internal events, running with this enabled will slow the table down considerably, and you should ensure you are only running this option with a table containing a small amount of data.