bradleyayers/django-tables2 — pull request #65 by christhekeele (2012-03-16 11:15:08+00:00)
Title: Support customized pagination in class-based views

Customization of a table's pagination is performed in the tables.paginate() method, through a set of arguments passed in to it (klass, per\_page, and page) along with extra *args and **kwargs getting shuttled to the provided Pagination klass. These values are given to tables.paginate() from the RequestConfig class, through a dictionary instantiated as 'paginate', allowing pagination to be customized.

Previously, there was no easy way to populate the paginate dictionary from the class based views, since people using the new views don't instantiate RequestConfig themselves. By implementing the SingleTableMixin.get\_paginate() method, I've exposed the paginate dictionary to the SingleTableView.as\_view() function, so people can use the standard class based plug in work flow.

get\_paginate() behaves like the other get_ methods within the view, uses duck typing to match dictionary-like objects (if for some reason people get really fancy), and acts the way RequestConfig expects it to:

* if the paginate dictionary isn't set, it defaults to true
* example: `SingleTableView.as_view(template_name="cool_tables.html", model=Coolness, table_class=CoolTable)`
* if set to true (or defaulting to it), default pagination will be used
* example: `SingleTableView.as_view(template_name="cool_tables.html", model=Coolness, table_class=CoolTable, paginate=True)`
* if set to false, tables.paginate()'s default of paginating will be disabled.
* example: `SingleTableView.as_view(template_name="cool_tables.html", model=Coolness, table_class=CoolTable, paginate=False)`
* if set to a dictionary, tables.paginate() will receive it when called and behave however people ask it to.
* example: `SingleTableView.as_view(template_name="cool_tables.html", model=Coolness, table_class=CoolTable, paginate=dict(per_page=42, klass=SuperPaginator, page=some_start_page, extra=will_get_passed_to_super_paginator)`

I've written this because django-tables2 seems preferable to other ordered paginated table plugins, gives you tons of control over styling, is actually maintained, and [bradleyayers](https://github.com/bradleyayers) is awesomely responsive; however I'm dealing with large datasets and class-based views, so I wanted to implement it with an ajaxified Paginator. I'm toying with a modified version of the standard tables.html file that plays nicely with django-endless-pagination. If I succeed, I'll throw that up into a push request, perhaps with logic in the djangotables2.RenderTableNode class to pick it if django-endless-pagination is discovered. From there it should be pretty easy to add defaults for all the major pagination plugins that inherit from django's Paginator.