In django-tables2, does the number of rows displayed depend on the size of the screen?

When using django-tables2, use the paginate parameter to limit the number of rows displayed. For example, if I have a my_table , then in views.py I set it to display 10 rows as follows:

 RequestConfig(request, paginate={'per_page':10}).configure(my_table) 

My problem is that in my application I want the number of lines shown on the page to depend on how big the user’s screen is. For example, 10 lines for mobile devices, but 25 lines for desktop screens. It seems to me that you are doing in views.py what you can do with style sheets using the multimedia rule (for example, @media(max-height: 480px) {do something} ).

Unfortunately, my understanding (noob) is that in Django, a view is relatively isolated from low-level options such as screen size. However, I do not want to implement some scheme, such as sending information from a template to a view, if there is already a simple solution, baked in django-tables2, which I simply do not know about.

Note. I use Bootstrap4 for my interface, if that matters. The thing is, I am already importing Javascript and jQuery into the project, at least at the template level.

Related General Discussion
Interestingly, I did not see much discussion of adapting the number of table rows to the type of multimedia, but obviously there is a subtle more general discussion of media-sensitive design:

+5
source share
1 answer

I do not have a simple or complete solution, but I will share some thoughts:

When (initially) creates a table, Django-tables2 has no way of knowing the size of the screen. One of these workarounds can suit your needs:

Show fewer lines

In your initial page view, if your screen size is small:

  • Hide multiple lines, then adjust the offset and the number of pages you request for the next pages using JavaScript. This will include rewriting the URL parameters of the page links.
  • Load the page with the lower number for per_page added to the URL.
  • By default, rendering has fewer lines and allows the user to change the number of lines displayed with a drop-down list, which is hidden for mobile users.

Optimize Responsive Template

Optimize the template for different screen sizes, and do not change the number of lines. An example of how this could work can be found in the table displayed in the web package documentation . However, you may need fewer lines for smaller screens using this technique.

Client side table sorting

If the total number of rows is reasonable, sending the entire client and delaying pagination into something like datatables might work.

+1
source

Source: https://habr.com/ru/post/1275324/


All Articles