Note that there are some explanatory texts on larger screens.

plurals
  1. POreinitialize datatables with external form data (server-side django app)
    primarykey
    data
    text
    <p>I am working on a django web app, and successfully implemented the fantastic jQuery datatables to present my data with server-side processing. I don't have access to the original files (this is a project for my workplace, they don't have internet access and I'm home now), but it looks something like this:</p> <p>template:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $('#example').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "/user_table/" } ); } ); &lt;/script&gt; &lt;table id='example'&gt; &lt;thead&gt; &lt;th&gt;name&lt;/th&gt; &lt;th&gt;state&lt;/th&gt; &lt;th&gt;email&lt;/th&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;td colspan="3" class="dataTables_empty"&gt;Loading data from server&lt;/td&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>server_side:</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() if request.GET.has_key('sSearch'): # filtering... query = query[start:start+length] response = ["aaData": [(q.name, q.state, q.email) for q in query]] # return serialized data </code></pre> <p>again, like I mentioned, I'm not having any trouble with this. The integration works fine. Even better than fine, really. I love it.</p> <p>What I really need though, is little more complex filter than the default one that datatables comes with. There are very specific types of search relevent for my work that will be very useful. So I have a form that appears vertically above the table. Let's say it looks something like this:</p> <pre><code>&lt;form&gt; &lt;label for='name'&gt;name:&lt;/label&gt; &lt;input type='text' name='name'&gt;&lt;/input&gt; &lt;label for'costumer'&gt;costumer?&lt;/label&gt; &lt;input type='checkbox' name='costumer'&gt;&lt;/input&gt; &lt;select multiple="multiple"&gt; &lt;option id='regular'&gt;regular&lt;/option&gt; &lt;option id='new'&gt;new&lt;/option&gt; &lt;/select&gt; &lt;input type='submit' value='filter!'&gt; &lt;/input&gt; &lt;/form&gt; </code></pre> <p>I want that when a user clicks on the submit button it would send the form data and re-initialize the datatable with my costumized filtering. Then I want another button that would refresh and reload the datatable and cancel out any initial data it was sending (as if you refreshed the page, without actually).</p> <p>I'm not very experienced with javascript, so simple solutions are the best, but any help would be very much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload