CDS.js_on_change not called, but CDS.on_change is

Hi,
I have a CDS which fires a python callback, but not the JS callback. I am under the impression that both should fire at the same event. In the example below when I modify a cell in the DataTable, the python callback is called, but the JS callback is not.

from bokeh.models import DataTable, ColumnDataSource, CustomJS, TableColumn
from bokeh.plotting import curdoc

source = ColumnDataSource(data = { 'x':[0,1,2,3], 'y':['a','b','c','d']})
columns = [TableColumn(field='x'), TableColumn(field='y')]
data_table = DataTable(source=source,columns= columns, editable=True)

callback_hello_js = CustomJS(code='''
    // just logs to the console
    console.log('hello from js');
    ''')

def callback_hello_py(attr, old, new):
    print('hello from python')

source.on_change('data',callback_hello_py)
source.js_on_change('data',callback_hello_js)

curdoc().add_root(data_table)

Seems like something to discuss and figure out, please file a GitHub issue with all this information.

Normally, events are only fired when the entire value of a property changes, not when a subitem (e.g. when all of .data is re-assigned, not when a single buried inside .data changes changes). So offhand I’m not sure the python property should be triggering a callback here, when a single element in the table column is changed. The best solution might be to make things consistent with the rest of bokeh and making the python property not fire (consistency is good), but adding some other event that can be watched for “subitem” changes since in this specific case of the table (it’s a common need).

Done.
Issue #9613
Yeah, ideally I would like a way to trigger a callback on the “subitem” changes.
Thanks

1 Like

Thanks, I definitely agree there should be some way, I was only stating that, for the sake of API consistency, perhaps it should not be on_change('data', ...) or js_on_change('data', ...)