Version 5, last updated by jarrod.neven at September 07, 2010 03:13 UTC

Datatables_demo is a demonstration of the jQuery plug in, datatables with server side datasource from Django. The demonstration contains a working demo Django project complete with HTML, CSS and Javascript needed to implement a complete working same.

 

This demo is pretty self-explanatory. It uses only basic django configuration and, we believe, can be easily understood by django-beginners.

 

Django datatables usage:

To implement this code into your application, follow these steps:

  • Create an entry in urls.py and views.py that will server the HTML and JS needed for datatables
  • Create a separate url and view for returning a json object to datatables.
def get_surveys(request):
querySet = Survey.objects.all()
columnIndexNameMap = { 0: 'id', 1 : 'name', 2: 'description', 3: 'active', 4: 'created' }
jsonTemplatePath = 'qa/survey/json_surveys.txt'
return get_datatables_records(request, querySet, columnIndexNameMap, jsonTemplatePath)
  1. create a  queryset object for the model you wish the data to be drawn from (querySet)
  2. create a dict for the column names, in correct display order (columnIndexNameMap)
  3. return the response to get_datatables_records which is contained in utils.py