0

我在 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 来完成吗?

4

1 回答 1

0

最好的方法是使用jquery。

如果您有要排序的表格,该链接可以帮助您:

http://tablesorter.com/docs/

于 2013-06-06T06:29:04.423 回答