I'm trying to implement server side filtering using KendoUI grid and Flask-Restless web service.
My Datasource object looks like this:
var myDataSource = new kendo.data.DataSource({
transport: {
read: {
type: 'GET',
url: "http://localhost:5000/api/geo",
contentType: "application/json",
dataType: "json",
},
parameterMap: function(data, type) {
if (type == "read") {
// console.log(data.filter);
return {
page: data.page,
q: data.filter
}
}
},
},
schema: {
data: 'objects',
total: "num_results",
},
serverPaging: true,
serverFiltering: true,
pageSize: 100,
});
On the server side, I want to intercept the filtering parameters, modify them appropriately to fit the Flask-Restless query object format and pass them to the REST endpoint. However, if using GET request the flask.request.args object looks like a flattened-out dictionary which is tedious to parse. The following code within the preprocessor:
for key, value in flask.request.args.iteritems():
print '%s : %s' % (key, value)
produces:
q[filters][0][value] : 106
q[filters][1][field] : county_id
q[filters][1][operator] : eq
q[filters][1][value] : 107
q[filters][0][operator] : eq
q[filters][0][field] : county_id
q[logic] : and
I guess I have two questions: 1. Is it possible to use POST request for reading data from Flask-Restless endpoint? 2. if answer to #1 is yes: how to pass the data.filter object from the Kendo DataSource to the Flask-Restless web service?
I do have access to the flask.reguest.args (in case of GET request) inside the preprocessor however, the args structure represents nested objects as string keys like: 'q[filters][0][value]' which is difficult to parse. I hope there is a better approach.
Thanks!