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


In your, 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:, 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.header|safe }} {{ table.body|safe }}

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](

_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


Download files

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

Files for django-searchly-tables, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_searchly_tables-0.1-py2-none-any.whl (6.4 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size django-searchly-tables-0.1.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page