Skip to main content

djangorestframework-tabulator

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.

A computed or renamed serializer field (a SerializerMethodField, a source= field, anything without a same-named model field) needs a dict instead of a plain list, mapping the client-facing name to the real ORM lookup path(s):

filterset_fields = {
    'status': 'state',                        # renamed field
    'customer': ['customer__name', 'customer__id'],  # search both at once
}
ordering_fields = {
    'customer': ['customer__name', 'customer__id'],  # tie-break, in order
}

A list of paths is combined with OR when filtering (e.g. one customer column that matches on either a name or an id), and chained as tie-breakers, in that order, when sorting.

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

Metadata

Release files for djangorestframework-tabulator 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangorestframework-tabulator 0.1.3
File Size Uploaded Provenance Actions
djangorestframework_tabulator-0.1.3.tar.gz 16.8 kB Without provenance Details for djangorestframework_tabulator-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djangorestframework-tabulator 0.1.3
File Interpreter ABI Platform Actions
djangorestframework_tabulator-0.1.3-py3-none-any.whl Python 3 none any Details for djangorestframework_tabulator-0.1.3-py3-none-any.whl

Total release size: 30.8 kB

Release files / djangorestframework_tabulator-0.1.3.tar.gz

Download URL djangorestframework_tabulator-0.1.3.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7fd64245d62fa3fb81c29341951688b15f2661396112ec3c12b66f0a94151434
BLAKE2b-256 checksum
How to use checksums
75c390732fb6a4f821624e50f87fb344896ef2cdbdf25a3d6b4a34bb2574a053
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / djangorestframework_tabulator-0.1.3-py3-none-any.whl

Download URL djangorestframework_tabulator-0.1.3-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d746814efc86b728395595fa84fb444fea779d137f7f18c67efb9386c87b10d
BLAKE2b-256 checksum
How to use checksums
4e1c011f8e8aafb60ffa467fcf8f819575d4849ce4cce3793c6d20e174e01255
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for djangorestframework-tabulator 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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