DataTables server-side processing - echoing back draw() parameter (Python/Flask)
If DataTables is sending a new value for draw
to your server-- just read that value and send it back:
@app.route("/api/result")def result_json(): return jsonify(z)
Could just become (adjust the code if DataTables sends the values in some other way):
@app.route("/api/result")def result_json(): z.update({'draw': request.form.get('draw')}) return jsonify(z)
I'm not addressing that your code doesn't seem to do anything with filtering or searching, but at least it gives you a starting point to build from.
Update
From the XHR code you pasted-- it looks like DataTables is passing values in via querystrings-- so request.args.get('draw')
would be the way to access that draw
data-value.
The draw parameter is only used by DataTables to ensure that the Ajax returns from server-side processing requests are drawn in sequence by DataTables. To use features like sorting, filtering and paging you will have to set up your own system of querying your data based on the sent parameters that are passed by Datatables when server-side processing is used.
The default parameters are here. You can also include your own custom parameters to that object by manipulating the data object in the ajax call.