added columns.sortable() method
[django-tables2.git] / django_tables / tables.py
index e6c09ed82ce85b41a0b28cc739284efca1f64ef9..7a284a0a2be66b6f136c95942fb98a775af0dbb8 100644 (file)
@@ -421,6 +421,18 @@ class Columns(object):
         self._spawn_columns()\r
         return self._columns.keyOrder.index(name)\r
 \r
+    def sortable(self):\r
+        """Iterate through all sortable columns.\r
+\r
+        This is primarily useful in templates, where iterating over the full\r
+        set and checking {% if column.sortable %} can be problematic in\r
+        conjunction with e.g. {{ forloop.last }} (the last column might not\r
+        be the actual last that is rendered).\r
+        """\r
+        for column in self.all():\r
+            if column.sortable:\r
+                yield column\r
+\r
     def __iter__(self):\r
         """Iterate through all *visible* bound columns.\r
 \r