并不是我在 'render_table' 中的所有专栏都可以订购,我该怎么办?

not all my column in 'render_table' are orderable, what can i do?

我用django_tables2中的render_table写了一个table,其中包含4个headers(标题,删除,查看,导出),标题是可订购的,但另一个不是,问题是 render_table 在所有元素中使用 class orderable,我该如何编辑它?

在 HTML 我这样调用函数 :

    <!--  table -->
<div class="mt-3">
    {% render_table table %}
</div>

这是我的 table.py 脚本:

ENTRIES_TEMPLATE = "<a href='{% url 'form-entries' form=record.pk %}' class='btn btn-outline-info btn-small'><i class='fas fa-file'></i></a>"   
DELETE_TEMPLATE = "<a href='{% url 'dashboard-topic-delete' pk=record.pk %}' class='btn btn-outline-danger btn-small'><i class='fas fa-trash'></i></a>"
VIEW_TEMPLATE   = "<a href='{{record.pk}}' class='btn btn-outline-info btn-small'><i class='fas fa-edit'></i></a>"

EXPORT_TEMPLATE = """
<div class="btn-group">
    <button type="button" class="btn btn-outline-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Export
    </button>
    <div class="dropdown-menu">
        <a class="dropdown-item" href="{{record.get_export_url}}?type=CSV"><i class='fas fa-file-csv'></i> csv</a>
        <a class="dropdown-item" href="{{record.get_export_url}}?type=XLS"><i class='fas fa-file-excel'></i> xlsx</a>
    </div>
</div>
"""


# # id          = tables.LinkColumn('forms:form-update',kwargs={"pk":A("pk")})
responses     = tables.TemplateColumn(ENTRIES_TEMPLATE)
delete      = tables.TemplateColumn(DELETE_TEMPLATE)
view        = tables.TemplateColumn(VIEW_TEMPLATE)

export     = tables.TemplateColumn(EXPORT_TEMPLATE)



class Meta:
    model = Topic
    template_name = "django_tables2/bootstrap.html"
    fields = ("Title","view","responses","delete","export")

(只有 ENTRIES_TEMPLATE 需要可订购)

您可以为您不想订购的列设置 orderable=False

# responses will be orderable
responses = tables.TemplateColumn(ENTRIES_TEMPLATE)
# the following three fields won't be orderable
delete = tables.TemplateColumn(DELETE_TEMPLATE, orderable=False)
view = tables.TemplateColumn(VIEW_TEMPLATE, orderable=False)
export = tables.TemplateColumn(EXPORT_TEMPLATE, orderable=False)

有关详细信息,请参阅 django-tables2 docs on ordering