When using django-tables2, use the paginate
parameter to limit the number of rows displayed. For instance, if I have the table 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 app I want the number of rows shown per page to depend on how big the user's screen is. For instance, 10 rows for mobile devices, but 25 rows for desktop screens. I am imagining doing in views.py
what you can do with style sheets using the media rule (e.g., @media(max-height: 480px) {do something}
).
Unfortunately, my (noob) understanding is that in Django, the view is relatively insulated from low-level parameters like screen size. However, I don't want to implement some scheme like sending information from the template to the view if there is already a simple solution baked into django-tables2 that I am just ignorant of.
Note I am using Bootstrap4 for my front end, if that makes any difference. The point is that I am already importing Javascript and jQuery into the project, at least at the template level.
Related general discussion
Interestingly, I haven't seen a lot of discussion of adapting table row count to media type, but there is obviously tons of more general discussion of responsive media-sensitive design: