Hi,
How can I unselect all rows on a DataTable after selecting ?
regards
Hi,
How can I unselect all rows on a DataTable after selecting ?
regards
You mean manually or with a separate button?
Thank you,
Manually first, with separate button will be also useful.
regards
Manually you can just do what you do to select/unselect multiple rows. On Windows and Linux it’s usually done by holding Ctrl while clicking. So if a rows is selected, just Ctrl+click on it.
Alternatively, just construct DataTable
with selectable='checkbox'
, and then each row would have a checkbox that you can easily unselect.
How to do it with a button:
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import DataTable, TableColumn, ColumnDataSource, CustomJS, Button
cds = ColumnDataSource(dict(value=[1, 2, 3]))
dt = DataTable(columns=[TableColumn(field='value')], source=cds)
b = Button(label='Clear selection')
b.js_on_click(CustomJS(args=dict(cds=cds), code="cds.selected.indices = [];"))
curdoc().add_root(column(b, dt))
Just a follow up question, how can you select all rows with a button (or if possible also manually)? It doesnt work pressing CTRL + A in the table to select all points.
Is it possible manually?
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import DataTable, TableColumn, ColumnDataSource, CustomJS, Button
cds = ColumnDataSource(dict(value=[1, 2, 3]))
dt = DataTable(columns=[TableColumn(field='value')], source=cds)
b = Button(label='Select All')
b.js_on_click(CustomJS(args=dict(cds=cds), code="""
cds.selected.indices = [...Array(cds.attributes.data.value.length).keys()];
"""))
show(column(b, dt))
It should be possible, but it’s completely out of scope of Bokeh.
You can do it by creating a global JS event listener in your HTML template that intercepts the required keyboard shortcut and selects all rows of the table. More details with some JS examples: Document: keydown event - Web APIs | MDN