2013-06-06 22 views
0

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

+0

如果你不想刷新页面,然后是,使用jQuery;使用ajax。 – bozdoz

回答

0

最好的方法是使用jquery。

这个链接可以帮助你,如果你有表排序:

http://tablesorter.com/docs/

+0

你能给我举一个我上面提供的模板上的tablesorter的例子吗? – pynovice

+0

有一个例子,您只需要将此js文件添加到您的网站,并且您可以按照您的colums的名称进行排序。 – Silwest

+0

得到它的工作。谢谢 – pynovice

相关问题