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

0

Issue

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)

Solution

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

Answered By – Alasdair

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More