I overrode Ext.data.proxy.Server
So far it works for me. I'm not sure if there's any implication. It would be great if we could decide how we want the filters to be sent, since the default ExtJS approach is not friendly with REST common practices. In fact, some REST frameworks, e.g. Apigility, cannot apply validation right out of the box to param values sent as JSON.
ExtJS 5.1.1.451
Code:
Ext.define('Ext.overrides.data.proxy.Server',{
override: 'Ext.data.proxy.Server',
getParams: function(operation) {
alert('works');
if (!operation.isReadOperation) {
return {};
}
var me = this,
params = {},
grouper = operation.getGrouper(),
sorters = operation.getSorters(),
filters = operation.getFilters(),
page = operation.getPage(),
start = operation.getStart(),
limit = operation.getLimit(),
simpleSortMode = me.getSimpleSortMode(),
simpleGroupMode = me.getSimpleGroupMode(),
pageParam = me.getPageParam(),
startParam = me.getStartParam(),
limitParam = me.getLimitParam(),
groupParam = me.getGroupParam(),
groupDirectionParam = me.getGroupDirectionParam(),
sortParam = me.getSortParam(),
filterParam = me.getFilterParam(),
directionParam = me.getDirectionParam(),
hasGroups, index;
if (pageParam && page) {
params[pageParam] = page;
}
if (startParam && (start || start === 0)) {
params[startParam] = start;
}
if (limitParam && limit) {
params[limitParam] = limit;
}
hasGroups = groupParam && grouper;
if (hasGroups) {
// Grouper is a subclass of sorter, so we can just use the sorter method
if (simpleGroupMode) {
params[groupParam] = grouper.getProperty();
params[groupDirectionParam] = grouper.getDirection();
} else {
params[groupParam] = me.encodeSorters([grouper], true);
}
}
if (sortParam && sorters && sorters.length > 0) {
if (simpleSortMode) {
index = 0;
// Group will be included in sorters, so grab the next one
if (sorters.length > 1 && hasGroups) {
index = 1;
}
params[sortParam] = sorters[index].getProperty();
params[directionParam] = sorters[index].getDirection();
} else {
params[sortParam] = me.encodeSorters(sorters);
}
}
if (filterParam && filters && filters.length > 0) {
/* OVERRIDE STARTS */
Ext.Array.each(Ext.decode(me.encodeFilters(filters)), function(item){
params[item.property] = item.value;
});
/* OVERRIDE ENDS */
/* ORIGINAL CODE REMOVED
params[filterParam] = me.encodeFilters(filters);
*/
}
return params;
}
});