Reputation: 377
Because I use more dgrid objects then native dojo objects that interacts with a store, I want to switch to dstore instead of dojo.store.rest.
But when I use dstore
with adapter for the live-search (FilteringSelect) the query parameters got modified in a way that breaks my api: e.g. I type "foo" it sends a request to
/api?name=match=foo*
But I want:
/api?name=foo*
Like it is with dojo/store/rest
.
I think it comes from Filter class in dstore.
Is there a way to disable this Filter?
Upvotes: 1
Views: 208
Reputation: 12726
Here's how I deal with this, along with setting some defaults I use
define([
'dojo/_base/declare',
'dojo/query',
'dstore/Rest'
],
function (declare, query, Rest) {
var csrfHeader = query('meta[name="_csrf_header"]')[0].content,
csrfToken = query('meta[name="_csrf"]')[0].content,
headers = {
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json'
};
headers[csrfHeader] = csrfToken;
return declare('app.store.rest', [ Rest ], {
sortParam: 'sort',
rangeStartParam: 'offset',
rangeCountParam: 'limit',
ascendingPrefix: '%2B',
descendingPrefix: '%2D',
accepts: 'application/json',
headers: headers,
_renderFilterParams: function (filter) {
var _filter = this.inherited(arguments);
for(var i=0; i<_filter.length; i++) {
_filter[i] = _filter[i].replace('match=', '').replace('*', '');
}
return _filter;
}
});
});
Upvotes: 1
Reputation: 377
I found a way to achieve this behavior, I had to add a modified version of _renderFilterParams:
var store = new Rest({
target: '/api',
_renderFilterParams: function (filter) {
var type = filter.type;
var args = filter.args;
if (!type)
return [''];
if (type === 'string')
return [args[0]];
return [encodeURIComponent(args[0]) + '=' + encodeURIComponent(args[1])];
}
});
Upvotes: 0