3

I have a view deriving from SingleTableView.

Instructions for disabling pagination revolve around using a call to RequestConfig, however I don't have implemented in my view the function that takes the request parameter.

I have tried overriding the get_table_pagination() function in the view and the table_pagination attribute however this doesn't work.

class DetailBuildView(SingleTableView):
    template_name = 'shoppinglist/detailbuild.html'
    table_class = BuildLineTable
    table_pagination = None
    def get_table_pagination(self):
      return None

    def get_queryset(self):
        self.shoppinglist = get_object_or_404(ShoppingList, id=self.kwargs['shoppinglist'])
        return BuildLine.objects.filter(shopping_list=self.shoppinglist)
frankster
  • 1,529
  • 2
  • 16
  • 20
  • What pagination options do you want to set (or do you just want to disable pagination). It would be helpful if you showed the code you've tried, rather than just saying it doesn't work. – Alasdair Apr 10 '15 at 09:12
  • I want to disable pagination. I have incorporate the code for the view above. – frankster Apr 10 '15 at 10:13

2 Answers2

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
  • 298,606
  • 55
  • 578
  • 516
  • Yep I only tried overriding the method as setting the value on the attribute directly wasn't working. I can't believe it was as simple as False vs None! Thanks – frankster Apr 10 '15 at 10:30
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
PM 77-1
  • 12,933
  • 21
  • 68
  • 111