Skip to main content

Django-table-sort

pre-commit.ci status Documentation Status codecov django-table-sort python-versions django-versions license Code style: black Contributor Covenant downloads

Create tables with sorting links on the headers in Django templates.

Documentation, including installation and configuration instructions, is available at https://django-table-sort.readthedocs.io/.

The Django Table Sort is released under the BSD license, like Django itself. If you like it, please consider contributing!

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.

Metadata

Release files for django-table-sort 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-table-sort 0.6.0
File Size Uploaded Provenance Actions
django_table_sort-0.6.0.tar.gz 8.3 kB Without provenance Details for django_table_sort-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-table-sort 0.6.0
File Interpreter ABI Platform Actions
django_table_sort-0.6.0-py3-none-any.whl Python 3 none any Details for django_table_sort-0.6.0-py3-none-any.whl

Total release size: 16.9 kB

Release files / django_table_sort-0.6.0.tar.gz

Download URL django_table_sort-0.6.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dc66524ccb18e73f2ed57f98f7393605a6bea937c32bb9652823a8191797c480
BLAKE2b-256 checksum
How to use checksums
f74197495dd609d08c737e9cc69af7b9ea372b1ee4e814f168b2320e6ae64de7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.13 Linux/6.2.0-1011-azure

Release files / django_table_sort-0.6.0-py3-none-any.whl

Download URL django_table_sort-0.6.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab7a9b84813cedd9ef1ab2f867ee343aeaec9a18ae5489c341e368b1485c6adc
BLAKE2b-256 checksum
How to use checksums
03725d8406aa3126c2971a755e56f19fb3dd4a1861daac4a634e3333e8b75fbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.13 Linux/6.2.0-1011-azure

Security for django-table-sort 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page