Trigger JS callback on data table edit

Hello everyone,

I am in the following situation: I have a data table where I would like to trigger a CustomJS upon some data getting edited in my table when editable is set to true. Is that possible and if yes, how?

I tried data_table.source.js_on_change

But that didn’t work. Many thanks in advance!

Here’s an example: https://stackoverflow.com/a/61077234/564509

@p-himik Many thanks! I did not see that one when searching for it :slight_smile:

As an aside I feel like it used to be the case that source.js_on_change('data', ...) would work here, but I also think we had somehow gone out of our way to make that happen, and in retrospect it was inconsistent with how things work everywhere else (a change on .data means an assignment to .data, except here). So, I guess I am glad it only works now using the "patching" event. That said, I think there should probably be a dedicated event for table cell editing, since "patching" is a bit of an implementation detail. So please feel free to open a GH issue to discuss improvements.

Can you expand a bit on why patching is an implementation detail? What about streaming? Maybe they should be not fictitious attributes but rather proper events that could be handled with js_on_event?

I mean only that cell editors happen to implement their updates by calling source.patch because it is convenient. It’s not inconceivable that things could be implemented differently without using source.patch, if some requirements or other consideration comes up. Except, of course, that we paint ourselves in to a corner by not providing a purposeful, scoped event for cell editing that can be maintained independently of underlying implementation.

Ah, so the event would be on the table itself and not on the source, I see.