title: django datatables additional data from server to template
body: <p>So I have implemented the dataTables plugin with django server-side processing. Looks a little like this:</p>
  
  <p>template:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function() {
      $('#example').dataTable( {
          "bProcessing": true,
          "bServerSide": true,
          "sAjaxSource": "/datatable/"
      } );
  } );
  
  &lt;/script&gt;
  </code></pre>
  
  <p>views:</p>
  
  <pre><code>def main_view(request):
      return render_to_response('index.html')
  
  def datatables_view(request):
      start = request.GET['iDisplayStart']
      length = request.GET['iDisplayLength']
  
      query = myUser.objects.all()
      total = query.count()
  
      if request.GET.has_key('sSearch'):
          # filtering...
  
  
      query = query[start:start+length]
      response = {"aaData": [(q.name, q.state, q.email) for q in query],
                  "iTotalRecords": total,  
                  ...additional params for dataTable... }
  </code></pre>
  
  <p>Then I use json.dump to serialize the data and send it like so</p>
  
  <pre><code>s = json.dump(response)
  return HttpResponse(s.read())
  </code></pre>
  
  <p>this might be a little wrong, but that's because I'm not using my actual code but rather writing it down from memory. It isn't important if there's any mistakes here just get that this is the general idea... (also, I use json because I'm running this on django 1.5 where simplejson is deprecated).</p>
  
  <p>So like I said, this works fine. The url for the page works with the main_view and the datatables sends its ajax calls to datatables_view and everything ticks. Now I want to send some additional data <em>from</em> the server (and not <em>to</em> the server). As in, I want to add some data to be used inside the template. This data has to come from the datatables_view because it relies on the current query and should be dynamic. say I add this to the response:</p>
  
  <pre><code>    response = {"aaData": [(q.name, q.state, q.email) for q in query],
                  "iTotalRecords": total,
                   ...additional params for dataTable...,
                  "sMeow": query.filter(name='cat')[:20]}
  </code></pre>
  
  <p>This is obviously an example, but the point is that when you change the query (say you filter by a search word or you change the ordering) then sMeow will <em>also</em> change. And then I want to access it somehow on the template. Obviously I can't just do this:</p>
  
  <pre><code>{{ sMeow }}
  </code></pre>
  
  <p>But I also can't use parseJSON because this isn't something that the documents receives, it's something that the <strong>datatable</strong> receives and I need to use the API to access it, though I can't find how to do that.  </p>
  
  <p>Since eventually I'd have a button that runs some script on the sMeow values (and send it to a different request) I had a look at the tabletools plugin but it doesn't really play well with server-side ("TableTools is more focused on the client-side" <a href="http://datatables.net/forums/discussion/837/tabletools-with-serverside-processing/p1" rel="nofollow">source</a>).</p>
  
  <p>I'm not shy from using additional plugins though I rather use the default capabilities of datatables. Any help would be appreciated!</p>