1

I have multiple tables in my documents_list view. Each of them has pagination (Django paginator) and when I click next button url changes, and table is hiding again. How can I fix this problem ?

P.S: I'm using Bootstrap tables, and when page is initializing all tables are hidden by default, after clicking according button table is showing. And I want stay on current table when changing page.

html:

...
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}">prev</a>
{% endif %}

<span class="current">
{{ page_obj.number }}
</span>

{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
{% endif %}
</span>
</div>

views.py:

    ...
    claim_documents = ClaimDocument.objects.all().order_by('-created_date') 

    paginator = Paginator(claim_documents, 2)
    page = request.GET.get('page', 1)

    try:
        page_obj = paginator.page(page)
    except PageNotAnInteger:
        page_obj = paginator.page(1)
    except EmptyPage:
        page_obj = paginator.page(paginator.num_pages)

    context = {
        'page_obj': page_obj,
         ...
    }
Bob Reynolds
  • 929
  • 3
  • 8
  • 21
  • I would pass some argument to the url, like table=2 and check in javascript which table I want to be opened on page load – token Aug 31 '20 at 06:52

2 Answers2

0

I've used Datatables instead of customizind Django's pagination.

Bob Reynolds
  • 929
  • 3
  • 8
  • 21
0

Please try this. Here we using get_page method.

...
claim_documents = ClaimDocument.objects.all().order_by('-created_date') 

paginator = Paginator(claim_documents, 2)
page = request.GET.get('page')
paginator = Paginator(data, 10)
page_obj = paginator.get_page(page)
context = {
    'page_obj': page_obj,
     ...
}

This link may help you.

Riyas Ac
  • 1,553
  • 1
  • 9
  • 23