Skip to main content

Seamless integration between Django REST framework and Datatables ( with supporting Datatables editor

Project description


Build codecov-image Documentation Status Pypi version Python versions Django versions


This package provides seamless integration between Django REST framework and Datatables with supporting Datatables editor.

  • It handles searching, filtering, ordering and most usecases you can imagine with Datatables.
  • You don’t have to create a different API, your API still work exactly the same .

How to use


$ pip install djangorestframework-datatables-editor

If you need the functionality of the editor, you also need to download the data editor from here, the JS+CSS version, and put the downloaded files in static folder.


To enable Datatables support in your project, add 'rest_framework_datatables_editor' to your INSTALLED_APPS, and modify your REST_FRAMEWORK settings like this:

    'DEFAULT_PAGINATION_CLASS': 'rest_framework_datatables_editor.pagination.DatatablesPageNumberPagination',
    'PAGE_SIZE': 50,

For using Datatables editor you should use DatatablesEditorModelViewSet instead ModelViewSet or add EditorModelMixin to your views.

And that’s it !

Your API is now fully compatible with Datatables and will provide searching, filtering, ordering and pagination without any modification of your API code ! For using Datatables editor you should use DatatablesEditorModelViewSet instead ModelViewSet or add EditorModelMixin to your views.

Configuring Datatables and Datatables editor

  • The URL for connecting datatables is the URL of your view with ?format=datatables
  • The URL connecting datatables editor is the URL of your view with editor/
  • Full documentation is available on Read the Docs !
  • Also you’ll need download Datatables editor.

Example of HTML code:

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <title>Rolling Stone Top 500 albums of all time</title>
    <link rel="stylesheet" href="//">
    <link rel="stylesheet" type="text/css" href="">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="/static/css/editor.bootstrap4.min.css">
    <div class="container" style="font-size: .9em;">
        <div class="row">
            <div class="col-sm-12">
                <table id="albums" class="table table-striped table-bordered" style="width:100%">
                        <th>Album name</th>
    <script src="//"></script>
    <script src="//"></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src="/static/js/dataTables.editor.js"></script>
    <script src="/static/js/editor.bootstrap4.min.js"></script>
        $(document).ready(function () {
            editor = new $.fn.dataTable.Editor({
                ajax: "/api/albums/editor/?format=datatables",
                table: "#albums",
                fields: [{
                    label: "rank",
                    name: "rank",
                }, {
                    label: "artist:",
                    name: "",
                    type: "select"
                }, {
                    label: "name:",
                    name: "name",
                }, {
                    label: "year:",
                    name: "year",
            var table = $('#albums').DataTable({
                "serverSide": true,
                dom: "Bfrtip",
                "ajax": "/api/albums/?format=datatables",
                "columns": [
                    {"data": "rank", "searchable": false},
                    {"data": "", "name": ""},
                    {"data": "name"},
                    {"data": "year"},
                    {"data": "genres", "name": "", "sortable": false},
                select: true,
                buttons: [
                    {extend: "create", editor: editor},
                    {extend: "edit", editor: editor},
                    {extend: "remove", editor: editor}
                .appendTo($('.col-md-6:eq(0)', table.table().container()));


The project is based on the project django-rest-framework-datatables by David Jean Louis


  • Python (2.7, 3.4, 3.5, 3.6, 3.7, 3.8)
  • Django (1.9, 1.11, 2.0, 2.1, 2.2, 3.0)
  • Django REST Framework (3.9, 3.10, 3.11)

Example project

To play with the example project, just clone the repository and run the dev server.

$ git clone
$ cd DRF-datatables-editor
Activate virtualenv.
$ pip install -r requirements-dev.txt
$ python example/ runserver
$ firefox


Install development requirements.

$ pip install -r requirements-dev.txt

Run the tests.

$ python example/ test

You can also use the excellent tox testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:

$ tox

If you want to check the coverage, use:

$ coverage run ./example/ test
$ coverage report -m


Version 0.3.3 (2020-05-17):

  • Added support for Django 3.0

Version 0.3.2 (2019-05-23):

  • Fixed checking fields when deleting

Version 0.3.1 (2019-05-22):

  • Fixed requirements

Version 0.3.0 (2019-05-06):

  • Added checking of the writable fields of Datatables Editor passed to Django
  • Added information about CSRF authorization to the documentation

Version 0.2.1 (2019-04-29):

  • Added documentation

Version 0.2.0 (2019-04-20):

  • Added tests for editor functionality

Version 0.1.0 (2019-04-15):

Version 0.5.0 (2019-03-31):

The changelog bellow is the changelog of django-rest-framework-datatables by David Jean Louis)

  • Fixed total number of rows when view is using multiple filter back-ends
  • New meta option datatables_extra_json on view for adding key/value pairs to rendered JSON
  • Minor docs fixes

Version 0.4.1 (2018-11-16):

  • Added support for Django 2.1 and DRF 3.9
  • Updated README

Version 0.4.0 (2018-06-22):

  • Added top level filtering for nested serializers
  • Added multiple field filtering
  • Added a ?keep= parameter that allows to bypass the filtering of unused fields
  • Better detection of the requested format
  • Fixed typo in Queryset.count() method name

Version 0.3.0 (2018-05-11):

  • Added a serializer Meta option datatables_always_serialize that allows to specify a tuple of fields that should always be serialized in the response, regardless of what fields are requested in the Datatables request
  • Optimize filters
  • Use AND operator for column filtering instead of OR, to be consistant with the client-side behavior of Datatables

Version 0.2.1 (2018-04-11):

  • This version replaces the 0.2.0 who was broken (bad

Version 0.2.0 (2018-04-11):

  • Added full documentation
  • Removed serializers, they are no longer necessary, filtering of columns is made by the renderer

Version 0.1.0 (2018-04-10):

Initial release.

Download files

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

Files for djangorestframework-datatables-editor, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size djangorestframework_datatables_editor-0.3.3-py2.py3-none-any.whl (11.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size djangorestframework-datatables-editor-0.3.3.tar.gz (12.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page