Attribute that captures the ordering of the data in a bokeh DataTable

Is there an attribute of bokeh.models.widgets.tables.DataTable, or the underlying ColumnDataSource, that indicates the order of the data? I would like to have the columns of a bar chart reorder when the table is sorted by clicking on the column headers, but I can’t find any attribute that I can use to trigger the figure update.

For example:

`import pandas as pd
from bokeh.models.sources import ColumnDataSource
from bokeh.models.widgets.tables import DataTable, TableColumn
from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.io import curdoc

df = pd.DataFrame({‘x’: [‘a’, ‘b’, ‘c’],
‘y’: [1, 2, 3]})

source = ColumnDataSource(df)

my_table = DataTable(source=source,
columns=[TableColumn(field=x, title=x) for x in source.column_names])

my_figure = figure(x_range=source.data[‘x’])
my_figure.vbar(x=‘x’,
top=‘y’,
width=0.9,
source=source)

l = layout([my_table, my_figure])

curdoc().add_root(l)`

Hi,

The underlying data in the CDS is never re-ordered, it is only displayed in a different order by the underlying SlickGrid table based on an index that is computed on every sort. There are currently no Bokeh model properties that expose this information because the information is a property of a view, not a model. It would be appropriate to open a GH issue to discuss the possibility of making this visible somehow.

I will say, there is probably some way to get at this information, there is a global index of Bokeh views somewhere, and it would be possible in theory to root around that and then access the index on the private DataProvider attribute of the DataTable view, but I would not recommend it.

Thanks,

Bryan

···

On Wednesday, February 27, 2019 at 8:01:08 AM UTC-8, Elliot Bernstein wrote:

Is there an attribute of bokeh.models.widgets.tables.DataTable, or the underlying ColumnDataSource, that indicates the order of the data? I would like to have the columns of a bar chart reorder when the table is sorted by clicking on the column headers, but I can’t find any attribute that I can use to trigger the figure update.

For example:

`import pandas as pd
from bokeh.models.sources import ColumnDataSource
from bokeh.models.widgets.tables import DataTable, TableColumn
from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.io import curdoc

df = pd.DataFrame({‘x’: [‘a’, ‘b’, ‘c’],
‘y’: [1, 2, 3]})

source = ColumnDataSource(df)

my_table = DataTable(source=source,
columns=[TableColumn(field=x, title=x) for x in source.column_names])

my_figure = figure(x_range=source.data[‘x’])
my_figure.vbar(x=‘x’,
top=‘y’,
width=0.9,
source=source)

l = layout([my_table, my_figure])

curdoc().add_root(l)`