【问题标题】:How to make the django-tables2 render all the column headers to text not the links如何使 django-tables2 将所有列标题呈现为文本而不是链接
【发布时间】:2012-03-21 10:37:36
【问题描述】:

在 django-tables2 中,默认所有表列都支持排序。这意味着所有列标题都呈现为链接,允许用户调整表数据的顺序。但我不想将列标题呈现给链接,该怎么做?

这是文件!

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

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

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

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

class SimpleTable(tables.Table):
    name = tables.Column()
    rating = tables.Column(orderable=True)

    class Meta:
        orderable = False

我这样做了,但它不起作用。这是我的 talbes.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"}

【问题讨论】:

    标签: python html django django-tables2


    【解决方案1】:

    the documentation:

    禁用特定列的排序

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

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

    • Table.Meta.orderable = False -- 默认禁用列排序
    • Column(orderable=False) -- 禁用特定列的排序,例如 禁用除一个以外的所有列:

    看看the template如何决定一个列是否应该有订单链接:{% if column.orderable %}

    【讨论】:

    • 我这样做了,但它不起作用。class Meta: orderable = False
    • 我知道了,我的 django_tables2 的版本是 0.9.4,不支持订购。现在我将它升级到 0.10.0,它可以工作了,谢谢。
    • @amkore 是的,您需要小心使用正确的文档和正确版本的 django-tables2。在 0.9.4 中,该选项被称为 sortable,我在 0.10.0 中将其重命名为 orderable
    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    相关资源
    最近更新 更多