Dash 排序 editable table,但对用户隐藏排序选项
Dash Sort editable table, but hide sort options from users
我有一个破折号 table。 Table 允许编辑。我想按列对 table 进行排序,这样如果用户输入数据,就会立即使用 table。我在页面 https://dash.plotly.com/datatable/callbacks 上实现了这一点。页面加载时已设置排序。我卡在了最后一步,我想对用户隐藏排序选项。这可能吗?
图片上的示例。我想删除标记为黄色的箭头,但仍按 'pop'.
列排序
来自 https://dash.plotly.com/datatable/callbacks 的已编辑代码示例:
import dash
from dash.dependencies import Input, Output
import dash_table
import pandas as pd
app = dash.Dash(__name__)
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')
PAGE_SIZE = 5
app.layout = dash_table.DataTable(
id='table-multicol-sorting',
columns=[
{"name": i, "id": i} for i in sorted(df.columns)
],
data=df.to_dict('records'),
page_size=PAGE_SIZE,
sort_action='native',
sort_mode='multi',
sort_as_null=['', 'No'],
sort_by=[{'column_id': 'pop', 'direction': 'asc'}],
editable=True,
)
if __name__ == '__main__':
app.run_server(debug=True)
您可以使用 css
定位排序元素并隐藏它:
span.column-header--sort {
display: none;
}
例如,您可以将该代码放入 assets
目录中的 css
文件中。有关在仪表板应用程序中包含样式的方法的更多信息,请参阅文档 here。
我可以通过 sort_action='none'
在 Dash v1.16.2
中完成
我有一个破折号 table。 Table 允许编辑。我想按列对 table 进行排序,这样如果用户输入数据,就会立即使用 table。我在页面 https://dash.plotly.com/datatable/callbacks 上实现了这一点。页面加载时已设置排序。我卡在了最后一步,我想对用户隐藏排序选项。这可能吗?
图片上的示例。我想删除标记为黄色的箭头,但仍按 'pop'.
列排序来自 https://dash.plotly.com/datatable/callbacks 的已编辑代码示例:
import dash
from dash.dependencies import Input, Output
import dash_table
import pandas as pd
app = dash.Dash(__name__)
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')
PAGE_SIZE = 5
app.layout = dash_table.DataTable(
id='table-multicol-sorting',
columns=[
{"name": i, "id": i} for i in sorted(df.columns)
],
data=df.to_dict('records'),
page_size=PAGE_SIZE,
sort_action='native',
sort_mode='multi',
sort_as_null=['', 'No'],
sort_by=[{'column_id': 'pop', 'direction': 'asc'}],
editable=True,
)
if __name__ == '__main__':
app.run_server(debug=True)
您可以使用 css
定位排序元素并隐藏它:
span.column-header--sort {
display: none;
}
例如,您可以将该代码放入 assets
目录中的 css
文件中。有关在仪表板应用程序中包含样式的方法的更多信息,请参阅文档 here。
我可以通过 sort_action='none'
在 Dash v1.16.2