Purpose of dataSource events, selectedElement events?

datatables not only have user events (like selecting a row), but also, dataSource and selected element events. the dataSource and selected element events seem to be the same as what would be triggered by an on select, namely, changing the selected row.

Hello Mikey!

They look the same, but the used events will depend on what you want to follow-up in your datatable. For example, if you want to call some function after selecting an element in your datatable, then the onSelect action is the way to go for that. If you want to stalk the behavior of your selection after performing a given event, then use the onChange action on your datasource, else if you want to do some actions on your selected element once it changes, then you should go for the onChange action of the selected element.

.

The reason I ask is because I cannot think of a situation where one will trigger, but the others will not.

For the function set on the onSelect event of the table, you’ll have to manually select the row for it to be executed.

For example, in this case, once we select an item from this datatable, we switch the display between the matrix and some picture, on the right panel, or for any other visual effects.

(These screenshots are available in the Event Planning template)

For the onChange actions on both the datasource and the selected element, the functions that you will assign there, wil be trigerred automatically whenever those latters change, so you won’t have to select something from the datatable for the events to be executed.

For the datasource, suppose you want to get the statistics of some selection for example, and you want it to be recomputed every time the selection displayed in your datatable changes, then you can link your function that does that calculus, in the onChange event of the datasource, and by this, whenever the datasource changes, those statistics will be automatically recomputed.

Same thing for the selected element, the function will be re-executed each time that latter changes.

These are just samples, the ideas and use cases might defer, depending on what you want to do.

1 Like