django-table-sort


Namedjango-table-sort JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/TheRealVizard/django-table-sort
SummaryCreate tables with sorting links on the headers in Django templates.
upload_time2023-09-17 18:34:12
maintainer
docs_urlNone
authorTheRealVizard
requires_python>=3.9
licenseBSD-3-Clause
keywords django table sort templates
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django-table-sort

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/TheRealVizard/django-table-sort/main.svg)](https://results.pre-commit.ci/latest/github/TheRealVizard/django-table-sort/main) [![Documentation Status](https://readthedocs.org/projects/django-table-sort/badge/?version=latest)](https://django-table-sort.readthedocs.io/en/latest/?badge=latest) [![codecov](https://codecov.io/gh/TheRealVizard/django-table-sort/branch/main/graph/badge.svg?token=KGXHPZ6HOB)](https://codecov.io/gh/TheRealVizard/django-table-sort) ![django-table-sort](https://img.shields.io/pypi/v/django-table-sort?color=blue) ![python-versions](https://img.shields.io/pypi/pyversions/django-table-sort) ![django-versions](https://img.shields.io/pypi/frameworkversions/django/django-table-sort?label=django) ![license](https://img.shields.io/pypi/l/django-table-sort?color=blue) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) ![downloads](https://img.shields.io/pypi/dm/django-table-sort)

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!](./CONTRIBUTING.md)

## Installation

**First**, install with pip:

```bash
pip install django-table-sort
```

**Second**, add the app to your INSTALLED_APPS setting:

```python
INSTALLED_APPS = [
    ...,
    "django_table_sort",
    ...,
]
```

## Usage
**First**, add the static to your Template:

```html
<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.

```html
<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:

```python
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:

```html
{{ table.render }}
```

Result:

The table is render with 2 link, one to Toggle the sort direction and another to remove the sort.

<p align="center">
    <img width="375" height="149" src="https://github.com/TheRealVizard/django-table-sort/raw/main/result.png">
</p>

You can filter by each field you declare as a column.
<p align="center">
    <img width="375" height="45" src="https://github.com/TheRealVizard/django-table-sort/raw/main/url_result.png">
</p>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TheRealVizard/django-table-sort",
    "name": "django-table-sort",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "django,table,sort,templates",
    "author": "TheRealVizard",
    "author_email": "vizard@divineslns.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/41/97495dd609d08c737e9cc69af7b9ea372b1ee4e814f168b2320e6ae64de7/django_table_sort-0.6.0.tar.gz",
    "platform": null,
    "description": "# Django-table-sort\n\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/TheRealVizard/django-table-sort/main.svg)](https://results.pre-commit.ci/latest/github/TheRealVizard/django-table-sort/main) [![Documentation Status](https://readthedocs.org/projects/django-table-sort/badge/?version=latest)](https://django-table-sort.readthedocs.io/en/latest/?badge=latest) [![codecov](https://codecov.io/gh/TheRealVizard/django-table-sort/branch/main/graph/badge.svg?token=KGXHPZ6HOB)](https://codecov.io/gh/TheRealVizard/django-table-sort) ![django-table-sort](https://img.shields.io/pypi/v/django-table-sort?color=blue) ![python-versions](https://img.shields.io/pypi/pyversions/django-table-sort) ![django-versions](https://img.shields.io/pypi/frameworkversions/django/django-table-sort?label=django) ![license](https://img.shields.io/pypi/l/django-table-sort?color=blue) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) ![downloads](https://img.shields.io/pypi/dm/django-table-sort)\n\nCreate tables with sorting links on the headers in Django templates.\n\nDocumentation, including installation and configuration instructions, is available at https://django-table-sort.readthedocs.io/.\n\nThe Django Table Sort is released under the BSD license, like Django itself. If you like it, please consider [contributing!](./CONTRIBUTING.md)\n\n## Installation\n\n**First**, install with pip:\n\n```bash\npip install django-table-sort\n```\n\n**Second**, add the app to your INSTALLED_APPS setting:\n\n```python\nINSTALLED_APPS = [\n    ...,\n    \"django_table_sort\",\n    ...,\n]\n```\n\n## Usage\n**First**, add the static to your Template:\n\n```html\n<link rel=\"stylesheet\" href=\"{% static 'django_table_sort.css' %}\"/>\n```\n\n`django-sort-table` uses by default Font Awesome 6 to display the icons, so you might need to add it too.\n\n```html\n<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\" />\n```\n\n**Second**, Use `django-table-sort` to display your tables.\n\nIn your _view.py_ file:\n\n```python\nclass ListViewExample(ListView):\n    model = Person\n    template_name: str = \"base.html\"\n    ordering_key = \"o\"\n\n    def get_ordering(self) -> tuple:\n        return self.request.GET.getlist(\n            self.ordering_key, None\n        )  # To make Django use the order\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"table\"] = TableSort(\n            self.request,\n            self.object_list,\n            sort_key_name=self.ordering_key,\n            table_css_clases=\"table table-light table-striped table-sm\",\n        )\n        return context\n```\n\nIn your _template.html_ file:\n\n```html\n{{ table.render }}\n```\n\nResult:\n\nThe table is render with 2 link, one to Toggle the sort direction and another to remove the sort.\n\n<p align=\"center\">\n    <img width=\"375\" height=\"149\" src=\"https://github.com/TheRealVizard/django-table-sort/raw/main/result.png\">\n</p>\n\nYou can filter by each field you declare as a column.\n<p align=\"center\">\n    <img width=\"375\" height=\"45\" src=\"https://github.com/TheRealVizard/django-table-sort/raw/main/url_result.png\">\n</p>\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Create tables with sorting links on the headers in Django templates.",
    "version": "0.6.0",
    "project_urls": {
        "Documentation": "https://django-table-sort.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/TheRealVizard/django-table-sort",
        "Repository": "https://github.com/TheRealVizard/django-table-sort"
    },
    "split_keywords": [
        "django",
        "table",
        "sort",
        "templates"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03725d8406aa3126c2971a755e56f19fb3dd4a1861daac4a634e3333e8b75fbb",
                "md5": "17669456f23afd67924c2452011fc772",
                "sha256": "ab7a9b84813cedd9ef1ab2f867ee343aeaec9a18ae5489c341e368b1485c6adc"
            },
            "downloads": -1,
            "filename": "django_table_sort-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "17669456f23afd67924c2452011fc772",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8591,
            "upload_time": "2023-09-17T18:34:11",
            "upload_time_iso_8601": "2023-09-17T18:34:11.359554Z",
            "url": "https://files.pythonhosted.org/packages/03/72/5d8406aa3126c2971a755e56f19fb3dd4a1861daac4a634e3333e8b75fbb/django_table_sort-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f74197495dd609d08c737e9cc69af7b9ea372b1ee4e814f168b2320e6ae64de7",
                "md5": "3bcdc44bdda618ee9b1bb2e032ac89bf",
                "sha256": "dc66524ccb18e73f2ed57f98f7393605a6bea937c32bb9652823a8191797c480"
            },
            "downloads": -1,
            "filename": "django_table_sort-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3bcdc44bdda618ee9b1bb2e032ac89bf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8261,
            "upload_time": "2023-09-17T18:34:12",
            "upload_time_iso_8601": "2023-09-17T18:34:12.493406Z",
            "url": "https://files.pythonhosted.org/packages/f7/41/97495dd609d08c737e9cc69af7b9ea372b1ee4e814f168b2320e6ae64de7/django_table_sort-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-17 18:34:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TheRealVizard",
    "github_project": "django-table-sort",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-table-sort"
}
        
Elapsed time: 0.23002s