Create tables with sorting links on the headers in Django templates.
Project description
Django-table-sort
Create tables with sorting links on the headers in Django templates.
This is currently WIP, so many other features will come in future releases.
Installation
First, install with pip:
pip install django-table-sort
Second, add the app to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...,
"django_table_sort",
...,
]
Usage
First, add the static to your Template:
<link rel="stylesheet" href="{% static 'django_table_sort.css' %}"/>
django-sort-table
uses by default Font Awesome 6 to display the icons, so you might need to add it too.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
Second, Use django-table-sort
to display your tables.
In your view.py file:
class ListViewExample(ListView):
model = Person
template_name: str = "base.html"
ordering_key = "o"
def get_ordering(self) -> tuple:
return self.request.GET.getlist(
self.ordering_key, None
) # To make Django use the order
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["table"] = TableSort(
self.request,
self.object_list,
sort_key_name=self.ordering_key,
table_css_clases="table table-light table-striped table-sm",
)
return context
In your template.html file:
{{ table.render }}
Result:
The table is render with 2 link, one to Toggle the sort direction and another to remove the sort.
You can filter by each field you declare as a column.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-table-sort-0.4.0.tar.gz
.
File metadata
- Download URL: django-table-sort-0.4.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c4811e0d0b688bb22d16e8c1c74307a1742cc7cf0ca5b2d741920d63d3bed0d |
|
MD5 | 0c1c618daa01492b9851ac4634075fd6 |
|
BLAKE2b-256 | 1d3f3cf087051917884bdf61607c1a47edd4d4903e498d6f54555dff314275b6 |
File details
Details for the file django_table_sort-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: django_table_sort-0.4.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae0cfbeb277f4e82b481a2303c316d87c82dbd149a6360e73fed344383abdd5f |
|
MD5 | 7bc0704d2122a3414c3f12bebd41d40d |
|
BLAKE2b-256 | 5b75e343f18426761d3ec8579470a2276fef14961943741921dc0365a6d16594 |