Skip to main content

Django integration with jQuery DataTables.

Project description

Author:Tim Santor


Handle server side processing for datatables 1.10.x.

Getting It

To install Django DataTables Too, just use pip:

$ pip install django-datatables-too

To install the development version:

$ pip install git+

If you want to install it from source, grab the git repository and run

$ git clone
$ cd django-datatables-too
$ pip install .


from django.http import JsonResponse
from django.views.generic import View
from django_datatables_too.mixins import DataTableMixin

class DataTablesAjaxPagination(DataTableMixin, View):
    model = Report
    queryset = Report.objects.all()

    def _get_actions(self, obj):
        """Get action buttons w/links."""
        return f'<a href="{obj.get_update_url()}" title="Edit" class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></a> <a data-title="{obj}" title="Delete" href="{obj.get_delete_url()}" class="btn btn-danger btn-xs btn-delete"><i class="fa fa-trash"></i></a>'

    def filter_queryset(self, qs):
        """Return the list of items for this view."""
        # If a search term, filter the query
            return qs.filter(
                Q( |
                Q( |
                Q( |
        return qs

    def prepare_results(self, qs):
        # Create row data for datatables
        data = []
        for o in qs:
                'number': o.number,
                'title': Truncator(o.title).words(10),
                'state': o.state,
                'year': o.year,
                'published': o.published,
                'modified': o.modified,
                'actions': self._get_actions(o)
        return data

    def get(self, request, *args, **kwargs):
        context_data = self.get_context_data(request)
        return JsonResponse(context_data)

from django.urls import path

from . import views

app_name = 'reports'

urlpatterns = [


        views.DataTablesAjaxPagination.as_view(), name='report-list-ajax'),



    columnDefs: [{
        orderable: false,
        targets: -1
    }, ],

    // Ajax for pagination
    processing: true,
    serverSide: true,
    ajax: {
        url: '{% url "reports:report-list-ajax" %}',
        type: 'get',
    columns: [
        { data: 'number', name: 'number'},
        { data: 'title', name: 'title' },
        { data: 'state', name: 'state' },
        { data: 'year', name: 'year' },
        { data: 'published', name: 'published' },
        { data: 'modified', name: 'modified' },
        { data: 'actions', name: 'actions' }


0.1.0 2018‑09‑25

  • Initial release

0.1.1 2019‑08‑16

  • Fixed bug when DataTable was set to ordering: false in JavaScript

Project details

Download files

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

Files for django-datatables-too, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size django_datatables_too-0.1.3-py3-none-any.whl (5.8 kB) File type Wheel Python version py3 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