Skip to main content

CI Pypi version Python versions

Remote pagination and filtering for Tabulator on top of Django REST Framework.

Why this exists

Tabulator, in remote mode (pagination: "remote", filterMode: "remote", sortMode: "remote"), sends pagination/filtering/sorting using its own query string convention, and expects the response back in its own shape — neither matches what DRF ships out of the box (PageNumberPagination responds with {count, next, previous, results}; its filter_backends don’t understand nested bracketed keys). This package translates both sides. jQuery DataTables already has a mature DRF adapter (djangorestframework-datatables); no equivalent exists for Tabulator.

Usage

from rest_framework.generics import ListAPIView
from rest_framework_tabulator import TabulatorFilterBackend, TabulatorPagination

class DocumentListView(ListAPIView):
    queryset = Document.objects.all()
    serializer_class = DocumentSerializer
    pagination_class = TabulatorPagination
    filter_backends = [TabulatorFilterBackend]
    filterset_fields = ['number', 'status', 'issued_at']
    ordering_fields = ['issued_at', 'number', 'total']

Tabulator’s contract (confirmed against the source code of tabulator-tables/tabulator itself, not third-party documentation):

  • Request: page/size (pagination), sort[i][field]/ sort[i][dir] (sorting), filter[i][field]/filter[i][type]/ filter[i][value] (filtering) — an array value (the in type) is sent as filter[i][value][0], filter[i][value][1], etc.

  • Expected response: {"data": [...], "last_page": N}.

filterset_fields/ordering_fields on the view are allowlists of fields (same attribute names django-filter/rest_framework.filters .OrderingFilter already use, so they look familiar) — any field not declared there is silently ignored, on both the filter and the sort side. Leaving either one undeclared denies filtering/sorting entirely rather than allowing every field by default.

Supported filter types

Every filter type Tabulator ships is supported (confirmed against Filter/defaults/filters.js in the Tabulator source for the exact set of built-in types):

Tabulator type

Django lookup

=

exact

!=

negated exact

<, <=, >, >=

lt, lte, gt, gte

like

icontains

keywords

icontains (see note below)

starts

istartswith

ends

iendswith

regex

regex

in

in (array value)

smart

ported from Tabulator’s own smart filter

smarter

ported from Tabulator’s own smarter filter

keywords note: Tabulator’s client-side keywords filter also supports a custom word separator and an “all words must match” toggle (headerFilterFuncParams), but neither is sent to the server in remote mode — the ajax payload only ever carries {field, type, value}. It is approximated here as a plain substring match, same as like.

smart/smarter are a faithful port of Tabulator’s own filter functions, not a Django-specific addition: . matches any non-empty value, ! matches empty/null, a leading comparison operator does a numeric comparison, a leading = does an exact match, multiple whitespace-separated words become an AND of a substring match per word, AND/OR combine sub-expressions left to right (no operator precedence, same as the original), and anything else falls back to a substring match.

A value that doesn’t fit the field’s type (e.g. a non-numeric string against an integer field, or an invalid date) raises a DRF ValidationError — a clean 400 naming the offending field — instead of an unhandled 500. Django validates most field types eagerly, right when the filter is applied, so this is caught there rather than only when the queryset is evaluated.

License

MIT — see LICENSE.

Development

pip install -e '.[dev]'
pytest

Download files

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

Source Distribution

djangorestframework_tabulator-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

djangorestframework_tabulator-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file djangorestframework_tabulator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for djangorestframework_tabulator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0796b595de85bbc13b4517008eebf2a754bc65495de91e3b75015c475787e27
MD5 1681393df74dc846a04789f3e0b07ec4
BLAKE2b-256 ff015503896553894205c9d492c99e078f4b26c494a889c7868da6066279784a

See more details on using hashes here.

File details

Details for the file djangorestframework_tabulator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangorestframework_tabulator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22ef33de4a2c9014a5fd0521895bd611118547e9675a7b43628f80516f328e6d
MD5 58375dc4f460dbac47b7cc2ec06d1fc7
BLAKE2b-256 359eb703dffb30c8b79bc3c857a0a4ba73b9a09e18ff75e766d571e7a5ab2ea5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page