我列出在Django以表格的形式是这样的所有文件信息:如何在Django的模板中进行排序?
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
<tr>
<th width="5%" class="table-header-left"><a href="#"><span></span></a></th>
<th width="25%" class="table-header-repeat line-left"><a href="#"><span>File Name</span></a></th>
<th width="15%" class="table-header-repeat line-left"><a href="#"><span>Type</span></a></th>
<th width="15%" class="table-header-repeat line-left"><a href="#"><span>Size</span></a></th>
<th width="20%" class="table-header-repeat line-left"><a href="#"><span>Date Updated</span></a></th>
<th width="20%" class="table-header-options line-left"><a href="#"><span>Source</span></a></th>
</tr>
<form name="form" action="/delete_files/" method="post">
{% csrf_token %}
{% load endless %}
{% paginate limit files %}
{{ endless_pagination.utils.get_elastic_page_numbers }}
{% for choice in files %}
<tr>
<td><input type="checkbox" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /></td>
<td><label for="choice{{ forloop.counter }}">{{ choice.file_name }}</label></td>
<td>{{ choice.type }}</td>
<td>{{ choice.size }}</td>
<td>{{ choice.end_date }}</td>
<td>{{ choice.source }}</td>
</tr>
{% endfor %}
</table>
我想申请分拣日:filename, date, size
。我有作为一个CharField存储文件名,日期作为一个DateTimeField和大小为一个整数在Django?我不想刷新整个页面的排序。有什么办法做到这一点?这是我的想法:
1) Pass href to th into backend which do the order by clause and pass data into template.
2) Fill the data into template with sorted data.
或者可以使用jQuery来完成?
如果你不想刷新页面,然后是,使用jQuery;使用ajax。 – bozdoz