Server side processing with datatables and flask Server side processing with datatables and flask flask flask

Server side processing with datatables and flask


Server-side processing is a setting that requires you to have a database script capable of replicating a lot of the core functionality of DataTables on your own server/database to manage very large sets of data.

All the information that is being passed to your script (e.g. that long string of info) are the inputs you need to use to query the database to return a result for DataTables to render.

If you would prefer DataTables to load the data from your Flask endpoint and then manage all the processing internally make these modifications: remove the serverSide setting and add column configurations so your data ends up in the right place:

Javascript:

$(document).ready(function() {    $('#myTable').DataTable( {        "processing": true,        "ajax": "/page_test",        // add column definitions to map your json to the table        "columns": [            {data: "time"},            {data: "MeanCurrent"},            ...        ]    } );});

DataTable Initialization Options: if you click the "columns" button it shows you the various configurations each "column" accepts, whether it is sortable, orderable, custom rendering, etc...

Python:

from flask import jsonify@app.route('/page_test')def page_test():    return jsonify(meas[2])


2 potential issues:

1) Make sure you are not using the slim jQuery version. Slim jQuery doesn't have ajax, so if you inspect in the browser, you will see some error message like "h.ajax if not a function". This will just show "processing..." indefinitely. This had me stumped for awhile, because bootstrap uses the slim version of jQuery by default, and I was using bootstrap.

2) I am not an expert on datatables by any means, but I am playing around with it. To get data to show using server side, the data had to be formatted like this:

return_me = json.dumps({"data": [[1, 1.3478, 23.2223, ...]]})

i.e., I couldn't get it to work when returning a dictionary of column names...I had to specifically call it the dictionary field "data" and then give that all the values. It's possible I have gotten something incorrect here myself, but this is what worked.


Using flask, you will get a faster response than using C#.In Server Side Processing, You can send sorted/searched/header value via form in flask. 

In Flask, You can get datatable values using:

Datatabledata= request.form

In SSP,You can send additional data to flask using:

"data":function(data){ data.input="Text"}