Skip to main content

A simple Django app that adds search and sort to HTML tables.

Project description

# Django-Searchly-Tables

A simple Django app that adds search and sort to HTML tables.

I like using simple views, but it should work with class-based views as well (but I haven't tested it).

## Example

Add `searchly_tables` to your `INSTALLED_APPS`:

INSTALLED_APPS = (
...,
"searchly_tables",
)

In your view.py, import searchly_tables, add a new table to a view,
and specify for which model you would like to use it:

from django.shortcuts import render

from example.model import ExampleModel
from searchly_tables.tables import SearchlyTable

def view(request):
table = SearchlyTable(module="exampleapp.models", model="ExampleModel", field_filters=field_filters)
table.labels = {'baseField1': 'labelForBaseField1', 'foreignkey_relationship': 'labelForForeignKeyRelationship', 'baseField2': 'labelForBaseField2'}

# Optional links to models in fields
table.field_links = {'baseField2': ['app:view': 'url_parameter']}
if request.POST:
table.post(request.POST, filter=True, sort=True)
return render(request, 'example/table.html', {'table': table})

Then add the table to your template like this:

<form action="#" method=POST>
{% csrf_token %}
{{ table.searchbar|safe }}
<table>
{{ table.header|safe }} {{ table.body|safe }}
</table>
</form>

And that's it! Naturally, you can change the appearance of the table by applying CSS.

For instance `table.attrs['td'] = 'my_td_class'` would result in `<td class="my_td_class">` on all td elements in the table.
Django-searchly-tables currently only supports classes; sorry, no direct styles as of yet.
Also no direct access to a single element by id for most elements; the sole exception is `<td>`.

Here's the list of elements I use in the table:

> _thead_, _tbody_, _tr_, _th_, _td_, _input_, _button_, _select_, _option_

## FAQ

_Should I use this?_

Maybe? Probably not?

It's a super basic app with very little fuzz. The code is still all over the place.
If that's for you, cool. If you need more options in your tabling(?),
you should check out [django_tables2](https://django-tables2.readthedocs.io).

_Another table app? Haven't you heard about django\_tables2? It's way better and has tons of features!_

Yep, I agree. I even linked to it in my earlier answer!

_So, will this support feature X in the future? I really need that._

Probably not? I'm happy with the way it works now, apart from some minor issues (=code cleanup/documentation).
But you're welcome to fork it, if you need feature X. Or use django_tables2 (seriously, it's great!).


Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

django-searchly-tables-0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

django_searchly_tables-0.1-py2-none-any.whl (6.4 kB view details)

Uploaded Python 2

File details

Details for the file django-searchly-tables-0.1.tar.gz.

File metadata

  • Download URL: django-searchly-tables-0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for django-searchly-tables-0.1.tar.gz
Algorithm Hash digest
SHA256 c00a9b568ce0f857060612975cda8d6be290514916aa4d92644e5fff4dcf56b0
MD5 c0764a35cdff9eb8d614f62e3f223d56
BLAKE2b-256 2351649105ce5d6153737060d40adc2fe14c9e4dc668b367b17b10a070886f1d

See more details on using hashes here.

File details

Details for the file django_searchly_tables-0.1-py2-none-any.whl.

File metadata

  • Download URL: django_searchly_tables-0.1-py2-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for django_searchly_tables-0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 8749402746010c57221cba7a89ae434065e9367a09967eec8ba8c10f40756e60
MD5 834cfcf4acd3e0cd1d73119713bc96dc
BLAKE2b-256 24e1156ad156ec2cdcf8bfa72137f25fbef44da16dd596a5e37a3c2d3be32671

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