Skip to main content

Componente reutilizable para generar datatables en Django con soporte para htmx y Bootstrap

Project description

django datatable builder

Reusable component to generate dynamic datatables in Django projects, with Bootstrap support and customizable row actions.

PyPI version License: MIT


🚀 Features

  • Automatically generate HTML tables from Django QuerySets
  • Supports pagination, ordering, and search
  • Bootstrap-compatible out of the box
  • Custom row-level actions (edit, delete, etc.)
  • Easy integration into existing Django apps

📦 Installation

pip install django-datatable-builder

🛠️ Basic Usage

1.Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_datatable_builder',
]

2.Create a table class in your view:

from django_datatable_builder import DataTable

def datatable_view(request):
    devices = [
        {"id": 1, "name": "Router", "status": "Active"},
        {"id": 2, "name": "Switch", "status": "Inactive"},
    ]

    datatable_config = {
        "data": devices,
        "columns": ["Name", "Status"],
        "hidden": ["id"],
        "order": [[0, "asc"]],
        "table_id": "devices_table",
        "column_search": True,
        "button_dropdown": True,
        "button_url": {
            "Show_demo_1": {"link": {"url": "demo:datatable_view",}},
            "Show_demo_2": {"modal": {"url": "demo:datatable_view","params":"devices_id": "id"}}
        },
        "button_inline": {
            "Show_demo_3": {"link": {"url": "demo:datatable_view", "params": {"devices_id": "id"}}, "class": "btn btn-success float-end"},
        },
    }

    return render(request, "demo.html", {"datatable": DataTable(request, datatable_config)})

3.Render the table in your template:

{{ datatable|safe }}

📚 Documentation

DataTable Parameters

These are the main configuration options used to initialize and render a dynamic datatable.

Parameter Description
data A Django QuerySet or a list of dictionaries. This is the source of the table content.
columns A list of column names. Order must match the order of fields in data.
hidden A list of field names to hide from the table. Useful for keeping some values available in HTML without displaying them.
order Default ordering of the table. Format: [[column_index, "asc" or "desc"]] — e.g., [[0, "asc"]].
table_id The HTML id attribute of the table. Required for JavaScript initialization.
column_search A list of field names that should support column-specific search.
button_dropdown Set to true or false depending on whether you want to show a dropdown with action buttons per row.
button_urls Used with button_dropdown. Defines one or more buttons with types like "link" or "modal". Supports optional class, and params. See example below.
button_inline Used for inline buttons (outside dropdowns). Structure is similar to button_urls. Useful if you want more flexibility with custom buttons.

button_urls (used with dropdown buttons)

button_urls = {
    "Edit": {
        "modal": {
            "url": "/edit/",
            "params": {
                "id": "id"  # Uses the 'id' from each row in `data`
            }
            "class": "btn btn-sm btn-primary",
        }
    },
    "View": {
        "link": {
            "url": "/view/",
        }
        "class": "btn btn-sm btn-secondary"
    }
}

button_inline (buttons directly rendered in table row)

button_inline = {
    "Delete": {
        "modal": {
            "url": "/delete/",
            "params": {
                "id": "id"
            }
        }
    }
}

🤝 Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_datatable_builder-0.1.3.tar.gz (372.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_datatable_builder-0.1.3-py3-none-any.whl (378.3 kB view details)

Uploaded Python 3

File details

Details for the file django_datatable_builder-0.1.3.tar.gz.

File metadata

  • Download URL: django_datatable_builder-0.1.3.tar.gz
  • Upload date:
  • Size: 372.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for django_datatable_builder-0.1.3.tar.gz
Algorithm Hash digest
SHA256 98be5c6989c2ab5f58d2a04756a7fbaeeb84f1ee5cf29f859691098876c2ea72
MD5 1a2a4fe396fccb88588b9e3bb68c61a4
BLAKE2b-256 2b12d6cf2352bdc471f9e5bb2c535651fc63b0e7b2f056046d17cf33d7abf1a7

See more details on using hashes here.

File details

Details for the file django_datatable_builder-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_datatable_builder-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a718d94e75ab9c5550e847f915f8c7eaeaa6ed0a4b57f69ef9e5294436c9cd81
MD5 09ac278c8b30508a0d7a1badc4b89eaf
BLAKE2b-256 b2c4f66f3a4c3c4146a7b18e337d6f9c5e47b7e84dbf664dc0e1a0e5770d6191

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page