I am having some problems processing parameters sent by jQuery datatables 1.10 when server-side processing is enabled. I initialized the datatable in javascript side as follows:
var table = $('#mytable').DataTable( { "processing": true, "serverSide": true, "ajax": { 'url': url, 'type': 'POST' }, "columns": data } );
And get a POST request on a Flask based server using this:
@app.route('/data/<data_key>', methods=['POST']) def get_data(data_key): print request.form
To filter the data, I tried to look inside request.form, but the result was strange and could not be easily converted to an array of objects. I get something like this:
ImmutableMultiDict( [ ('columns[0][data]', u'ReportDate'), ('draw', u'1'), ('columns[1][name]', u''), ('columns[1][data]', u'FundName'), ('columns[0][orderable]', u'true'), ('columns[1][searchable]', u'true'), ('columns[1][orderable]', u'true'), ('order[0][column]', u'0'), ('columns[0][name]', u''), ('order[0][dir]', u'asc'), ('search[value]', u''), ('columns[1][search][regex]', u'false'), ('columns[0][search][value]', u''), ('search[regex]', u'false'), ('columns[1][search][value]', u''), ('columns[0][search][regex]', u'false'), ('start', u'0'), ('length', u'10'), ('columns[0][searchable]', u'true') ] )
The jQuery datatables documentation says:
The order parameters [i] and columns [i] that are sent to the server are arrays of information:
order [i] is an array that determines how many columns are ordered, that is if the length of the array is 1, then one column is sorted; otherwise, several columns are sorted.
columns [i] - an array defining all columns in the table.
In both cases, I am an integer that will change to indicate the value of the array. In most modern server-side scenarios, this data will automatically be available to you as an array.
However, Flask provides this data as a simple dictionary, is there a way to easily convert it to an array of objects?