I’m using a python api server (flask-restless) which uses the JSON api for filtering/sorting/pagination and am trying to get can-connect to work correctly with it.
I’ve read through the docs but its still not making sense in some cases. I’m probably just not understanding how can-set works with server based pagination/sorting etc.
sorting
The server accepts sorting parameters like this:
Ascending: sort=fieldName
Descending: sort=-fieldName
(note the -
)
I initially thought I’d do something like this:
connection.getList({
sort: {
field: 'fieldname',
type: 'asc'
}
});
and in my supermap, I could just override the getListData
method to send the sorting parameters, but while my api is returning a correct sorted result, I’m not sure how to configure can-set to handle it correctly. When I create my algebra, should I just set:
const algebra = new set.Algebra({
sort: function () {
console.log(arguments);
return true;
},
});
filtering
Filtering is a bit more complex, its not as simple as ?name="value"
instead the api accepts filters like:
filter[objects]=[{"val":"value", "op": "=", "name": "fieldname"}]
Same thing, should I just set algebra to:
'filter[objects]': function() {
return true;
}
pagination
pagination works like this:
page[number]=4
--sets the page to 4
page[size]=10
--sets the per page count to 10
So we’d be requesting items 40-49 with that request. Not necessarily ID number 40-49, just the 40th through 49th items.