Joh*_*ers 2 django django-tables2
我使用django-tables2显示数据库表.全部显示正常,但单击列标题不会按该列排序.标题是可点击的,但在它们的html中没有url文本,例如:
<div class="table-container">
<table class="paleblue"><thead><tr><th class="id orderable sortable"><a href="">ID</a>
</th><th class="orderable sortable system"><a href="">System</a></th> ...
Run Code Online (Sandbox Code Playgroud)
我检查了django-tables2模板源代码,它是这样的:
... <a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}"> ...
Run Code Online (Sandbox Code Playgroud)
哪个我不明白.
我只能通过在view.py中设置order_by来进行排序工作:
class ResultsTable(tables.Table):
class Meta:
model = Performance
attrs = {'class': 'paleblue'}
order_by_field = True
def result(request, system):
results = Performance.objects.filter(system__name=system)
table = ResultsTable(results, order_by=('<any column name from Performance>',))
RequestConfig(request).configure(table)
return render_to_response('result.html', {'table': table})
Run Code Online (Sandbox Code Playgroud)
但这显然只适用于一列,我想点击列来选择要排序的列.
从文档中我的理解是,按列排序应该"开箱即用",这是正确的,还是我做错了什么?
经历过同样的问题,只有我错过了
django.core.context_processors.request
Run Code Online (Sandbox Code Playgroud)
来自settings.py中的TEMPLATE_CONTEXT_PROCESSORS
| 归档时间: |
|
| 查看次数: |
2466 次 |
| 最近记录: |