如何在没有默认行填充颜色的情况下构建散景数据表?

How to build Bokeh datatable without default row fill colour?

Bokeh 中有没有一种方法可以在构建数据表时去除交替行背景格式?

from datetime import date
from random import randint

from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
from bokeh.io import output_file, show

output_file("data_table.html")

data = dict(idx=[randint(0, 100) for i in range(10)],
            values=[randint(0, 100) for i in range(10)])
source = ColumnDataSource(data)

columns = [TableColumn(field="idx", title="Index"),
           TableColumn(field="values", title="Values")]
data_table = DataTable(source=source, columns=columns, width=400, height=280)

show(data_table)

创建数据表时,其行以交替的白灰色填充显示,但对于我正在构建的特定数据表,我需要所有行都是 white/transparent,这在 Bokeh 中可以实现吗?

我在 Datatable documentation 中查找过,但似乎没有专门用于此的参数。有 background 参数,但在尝试以下选项后它不会影响生成的数据表:

from bokeh.colors.rgb import RGB

data_table = DataTable(source=source, columns=columns, width=400, height=280, background='red')
data_table = DataTable(source=source, columns=columns, width=400, height=280, background='#000000')
data_table = DataTable(source=source, columns=columns, width=400, height=280,
                       background=RGB(125, 54, 89))

有趣的是,当我提供一个无效参数(比如,background='000000')时,散景 returns 一个 ValueError 说明什么是可以接受的,其中包括:

ValueError: expected an element of either Enum(...'red',...),
Regex('^#[0-9a-fA-F]{6}$'),
Regex('^rgba\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,\s*?){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,\s*([01]\.?\d*?)\)'),
Regex('^rgb\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,\s*?){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*?\)'),
Tuple(Byte(Int, 0, 255), Byte(Int, 0, 255), Byte(Int, 0, 255)),
Tuple(Byte(Int, 0, 255), Byte(Int, 0, 255), Byte(Int, 0, 255), Percent) or RGB, got '000000'

是否有我在这里缺少的数据表的发起者?

另外,我知道有一个 可以用 HTMLTemplateFormatter 格式化单元格,但应该避免这种情况,因为我已经在为某些列使用格式选项。

没有内置方法可以做到这一点。但是您可以使用自定义文档模板并向其中添加一些 CSS 规则。灰色背景的行受此 CSS 规则约束:

.bk-root .slick-row.odd {
    background: #fafafa;
}