如何使数据表小部件仅支持单行选择? (禁用多行选择)。
答案 0 :(得分:0)
我想出了使用事件的破解/解决方法
import functools
def table_select_callback(source, attrname, old, new):
# the lists of indicies are in random order, sort them
new = sorted(new)
old = sorted(old)
if len(new) == 0:
# they selected 0 elements, return
return
elif len(new) == 1:
# they selected 1 element, return
return
elif len(old) == 0:
# this shouldn't be possible but it's JS. #YOLO
source.selected.indices = [new[0]]
source.selected.indices = [new[0]] if old[0] != new[0] else [new[-1]]
# table_source is your instance of ColumnDataSource or equiv
table_source.selected.on_change(
"indices",
functools.partial(
table_select_callback, table_source
),
)