【发布时间】:2021-10-14 21:41:30
【问题描述】:
我使用 django_tables2 中的 render_table 编写了一个包含 4 个标题(标题、删除、视图和导出)的表,标题是可排序的,但另一个不是,问题是 render_table 在所有元素中都使用可排序的类,我该如何编辑?
在 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 需要可订购)
【问题讨论】:
标签: django django-tables2