static and ModelTables.\r
\r
\r
+The table.columns container\r
+---------------------------\r
+\r
+While you can iterate through ``columns`` and get all the currently visible\r
+columns, it further provides features that go beyond a simple iterator.\r
+\r
+You can access all columns, regardless of their visibility, through\r
+``columns.all``.\r
+\r
+``columns.sortable`` is a handy shortcut that exposes all columns which's\r
+``sortable`` attribute is True. This can be very useful in templates, when\r
+doing {% if column.sortable %} can conflict with {{ forloop.last }}.\r
+\r
+\r
Tables and Pagination\r
---------------------\r
\r
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
assert books.page.has_previous() == False\r
assert books.page.has_next() == True\r
\r
+# TODO: all the column stuff might warrant it's own test file\r
def test_columns():\r
- """Test specific column features.\r
+ """Test Table.columns container functionality.\r
+ """\r
+\r
+ class BookTable(tables.Table):\r
+ id = tables.Column(sortable=False)\r
+ name = tables.Column(sortable=True)\r
+ pages = tables.Column(sortable=True)\r
+ language = tables.Column(sortable=False)\r
+ books = BookTable([])\r
\r
- Might warrant it's own test file."""\r
+ assert list(books.columns.sortable()) == [c for c in books.columns if c.sortable]\r
+\r
+\r
+def test_column_order():\r
+ """Test the order functionality of bound columns.\r
+ """\r
\r
class BookTable(tables.Table):\r
id = tables.Column()\r