Fixed issue #14 (misleading custom template docs).
authorBradley Ayers <bradley.ayers@gmail.com>
Sun, 10 Jul 2011 07:13:52 +0000 (17:13 +1000)
committerBradley Ayers <bradley.ayers@gmail.com>
Sun, 10 Jul 2011 07:13:52 +0000 (17:13 +1000)
docs/index.rst

index 7d5d33ace068b424d0608fef40564c4ac3028d7a..865ca60fa498b85293e4361eba5cb0368d94cdd8 100644 (file)
@@ -500,29 +500,57 @@ ignore the built-in generation tools, and instead pass an instance of your
 
 .. code-block:: django
 
+    {% spaceless %}
     {% load django_tables2 %}
-    <table>
+    {% if table.page %}
+    <div class="table-container">
+    {% endif %}
+    <table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %}>
         <thead>
-            <tr>
+            <tr class="{% cycle "odd" "even" %}">
             {% for column in table.columns %}
-                <th><a href="{% set_url_param sort=column.name_toggled %}">{{ column }}</a></th>
+            {% if column.sortable %}
+                {% with column.order_by as ob %}
+                <th class="{% spaceless %}{% if column.sortable %}sortable {% endif %}{% if ob %}{% if ob.is_descending %}desc{% else %}asc{% endif %}{% endif %}{% endspaceless %}"><a href="{% if ob %}{% set_url_param sort=ob.opposite %}{% else %}{% set_url_param sort=column.name %}{% endif %}">{{ column.header }}</a></th>
+                {% endwith %}
+            {% else %}
+                <th>{{ column.header }}</th>
+            {% endif %}
             {% endfor %}
             </tr>
         </thead>
         <tbody>
-            {% for row in table.rows %}
-            <tr>
+            {% for row in table.page.object_list|default:table.rows %} {# support pagination #}
+            <tr class="{% cycle "odd" "even" %}">
                 {% for cell in row %}
-                <td>{{ cell }}</td>
+                    <td>{{ cell }}</td>
                 {% endfor %}
             </tr>
             {% empty %}
-                {% if table.empty_text %}
-                <tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
-                {% endif %}
+            {% if table.empty_text %}
+            <tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
+            {% endif %}
             {% endfor %}
         </tbody>
     </table>
+    {% if table.page %}
+    <ul class="pagination">
+        {% if table.page.has_previous %}
+        <li class="previous"><a href="{% set_url_param page=table.page.previous_page_number %}">Previous</a></li>
+        {% endif %}
+        <li class="current">Page {{ table.page.number }} of {{ table.paginator.num_pages }}</li>
+        {% if table.page.has_next %}
+        <li class="next"><a href="{% set_url_param page=table.page.next_page_number %}">Next</a></li>
+        {% endif %}
+    </ul>
+    </div>
+    {% endif %}
+    {% endspaceless %}
+
+.. note::
+
+    This is a complicated example, and is actually the template code that
+    ``{% render_table %}`` uses.
 
 
 .. _template_tags: