Skip to main content

Python library that helps create searchable, custom filterable datatables

Project description

Jinja-Datatables

A python library to simplify rendering datatables in jinja templates

Note: This tool is in development and doesnt 100% work yet, all of it is untested

TODO

  • Write test for html
  • Add detail row functionality
  • Make filters an option

Install

pip install jinja-datatables

Usage

See this repo's tests folder for an example Currently only flask-ajax completed

1.) Create a table view object

There are currently three options

From Ajax

If you want to get all your data asynchronously from a endpoint you can create a datatable oject like this

from jinja_datatables.datatable_classes import DatatableColumn, AjaxDatatable
columns = [
    DatatableColumn("data_name", "Column Name", "filter_text"
]
endpoint = "/get_data"
table_view = AjaxDatatable(
    columns,
    None,
    None,
    endpoint,
)

From a JS array

If you have all your data defined in a JS array you can create a datatable object like this:

from jinja_datatables.datatable_classes import DatatableColumn, JSArrayDatatable
columns = [
    DatatableColumn("data_name", "Column Name", "text"),
]
js_array = "dataArray"
table_view = JSArrayDatatable(
    columns,
    None,
    None,
    js_array,
)

For your endpoint, make sure it returns just an array of your data, functionality to customize this behavior might be added in future

From HTML

This is completely untested

If you already have your table in html, then you can easily instantiate a datatable on it like this:

from jinja_datatables.datatable_classes import DatatableColumn, HTMLDatatable
columns = [
    DatatableColumn("data_name", "Column Name", "filter_text"),
]
table_view = HTMLDatatable(
    columns,
    None,
    None,
)

2.) Instantiate Jinja environment

from jinja2 import Environment
from jinja_datatables.jinja_extensions.datatableext import DatatableExt
env = Environment(extensions=[DatatableExt])

For flask this will be handled by attaching an extension like this:

app = Flask(__name__)  # , instance_relative_config=True)
app.jinja_options["extensions"].append(DatatableExt)

3.) Render Template

In python

template = env.get_template("datatable_template.html")
template.render(table_view=table_view)

In your template file

{% datatable table_view %}

Contributing

I have no idea how contributing works. Make a pull request? Send me a message?

I would greatly appreciate help on how to test this

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

jinja_datatables-0.0.8.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

jinja_datatables-0.0.8-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file jinja_datatables-0.0.8.tar.gz.

File metadata

  • Download URL: jinja_datatables-0.0.8.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for jinja_datatables-0.0.8.tar.gz
Algorithm Hash digest
SHA256 fc7b89925d11de06277a35381fc5cc22d70e42b73589ce20f67f3f78cf2211c1
MD5 1641cefb053414411382aeb13187f06b
BLAKE2b-256 ded1a427a4224b70ad06d7258640116a75ba272d1ff6d015f0e6d84a674b1eea

See more details on using hashes here.

File details

Details for the file jinja_datatables-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: jinja_datatables-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for jinja_datatables-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 98eb7df0b8ab651ced987c102d634e1ef9a618c26613fca8aa58a738d6896154
MD5 ae9f09cce149305a5f2eab45aa022395
BLAKE2b-256 9846a606e9726748589cb5c1feffd15e0b99524d18983ef1b8746d0c0b66a317

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