【问题标题】:Dash Sort editable table, but hide sort options from users短划线排序可编辑表格,但对用户隐藏排序选项
【发布时间】:2021-05-14 04:13:42
【问题描述】:

我有一个仪表板。表允许编辑。我想按列对表格进行排序,这样如果用户输入数据,表格就会立即被使用。我在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)

【问题讨论】:

    标签: python plotly-dash


    【解决方案1】:

    我可以在 Dash v1.16.2 中通过 sort_action='none' 来做到这一点

    【讨论】:

      【解决方案2】:

      您可以像这样使用css 定位排序元素并隐藏它:

      span.column-header--sort {
        display: none;
      }
      

      例如,您可以将该代码放在您的assets 目录中的css 文件中。请参阅文档here,了解有关在仪表板应用程序中包含样式的方法的更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-02
        • 2013-09-23
        • 1970-01-01
        • 2013-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多