[Django]-How do I control pagination using a class-based view in django-tables2?

2πŸ‘

βœ…

If you want to disable pagination, then you need to set table_pagination=False. Setting it to None means the view uses the default pagination.

class DetailBuildView(SingleTableView):
    template_name = 'shoppinglist/detailbuild.html'
    table_class = BuildLineTable
    table_pagination = False

Instead of setting table_pagination, you could override get_table_pagination as follows, but there isn’t any advantage in doing so.

    def get_table_pagination(self):
        return False
πŸ‘€Alasdair

1πŸ‘

Overwrite method paginate(..\django_tables2\tables.py) in YourTable(Table):

The lines that are with #, carry out the pagination, comment them and this is deactivated.

from django.core.paginator import Paginator

     def paginate(self, paginator_class=Paginator, per_page=None, page=1, *args, **kwargs):
        """
        Paginates the table using a paginator and creates a ``page`` property
        containing information for the current page.

        Arguments:
            paginator_class (`~django.core.paginator.Paginator`): A paginator class to
                paginate the results.

            per_page (int): Number of records to display on each page.
            page (int): Page to display.

        Extra arguments are passed to the paginator.

        Pagination exceptions (`~django.core.paginator.EmptyPage` and
        `~django.core.paginator.PageNotAnInteger`) may be raised from this
        method and should be handled by the caller.
        """

        #per_page = per_page or self._meta.per_page
        #self.paginator = paginator_class(self.rows, per_page, *args, **kwargs)
        #self.page = self.paginator.page(page)

        return self
πŸ‘€bryan villa

Leave a comment