Django create paging using Ajax

Asked

Viewed 289 times

1

I want to upload the pagination without refresh using ajax

I have a table where shows 5 items per page the goal is to change page not refresh the page to switch to the following

In the views: inserir a descrição da imagem aqui

In the pagination Nav template

inserir a descrição da imagem aqui

  • Unnecessary code has been cut, only the code that is required for paging

  • Utilize Datatable here. https://pypi.org/project/django-datatables-view/

2 answers

0

Django template language works by making new server-side requests, to load only the result through ajax you will need to create the javascript call and an api that returns the table items in json format. I suggest using some framework (Vue, angular etc) and creating a pagination component.

0

Django even has a pager that can be used but it will not do as you want, so the tip is to use Django REST Framework along with some solution in JS, for example Datatables (in this case it is necessary to use a library that takes care for the DRF to create a compatible JSON).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.