如何使Djangotables2将所有列标题呈现为文本而不是链接

2024-10-17 00:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

在django-tables2中,默认情况下所有表列都支持排序。这意味着所有列标题都被呈现为允许用户调整表数据顺序的链接。但我不希望列标题呈现为链接,如何做到这一点?在

这是文件!在

默认情况下,所有表列都支持排序。这意味着所有列标题都被呈现为允许用户调整表数据顺序的链接。在

可以基于表或列禁用排序。在

Table.Meta.orderable = False – default to disable ordering on columns
Column(orderable=False) – disable ordering for specific column

例如,禁用除一个以外的所有列:

^{pr2}$

我做过,但没有工作。这个是我的吗塔贝斯.py文件:

class MusicBaseTable(tables.Table):
    songs = tables.CheckBoxColumn()
    title = tables.Column()
    artist = tables.Column()
    album = tables.Column()
    genre = tables.Column()
    date = tables.Column()

    class Meta:
        orderable = False
        attrs = {"class": "list"}

Tags: 文件数据用户false标题tables排序顺序
1条回答
网友
1楼 · 发布于 2024-10-17 00:29:45

the documentation

Disabling ordering for specific columns

By default all table columns support ordering. This means that all the column headers are rendered as links which allow the user to adjust the ordering of the table data.

Ordering can be disabled on a table or column basis.

  • Table.Meta.orderable = False default to disable ordering on columns
  • Column(orderable=False) disable ordering for specific column e.g. disable columns on all but one:

请看the template如何决定列是否应该具有order链接:{% if column.orderable %}

相关问题 更多 >