Create tables with sorting on the headers in Django templates.
Project description
Django-table-sort
Create tables with sorting 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-sort-table
Second, add the app to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...,
"django-sort-table",
...,
]
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:
table = TableSort(
request,
Person.objects.all(),
column_names={"name": "Firs Name", "age": "Age in years"},
sort_key_name="o",
column_css_clases="text-center",
table_css_clases="table",
table_id="id_table",
)
return render(request, "base.html", {"table": table})
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.2.0.tar.gz
.
File metadata
- Download URL: django-table-sort-0.2.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.15.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04430ed9b5238867bddbabfc9e8e79f7c5ac6b1073e861fd89a669e5ecca05d4 |
|
MD5 | da4d475416bba1f2b01cd0aba0a377c6 |
|
BLAKE2b-256 | 6ef1375277b2536e480581632a580b317a6ec3a784e49fe1a0b396abf4583636 |
File details
Details for the file django_table_sort-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: django_table_sort-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.15.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e23daf25c4aa080b24a060745db1e16d1dbb9a15785746f41cc1fb05f2bd6b11 |
|
MD5 | 90eb61e4f9f4bc95f08fdd5e082534d9 |
|
BLAKE2b-256 | 587e5b454e47c1135412285868eae56259beba373116946dd1b28e30aa012e02 |