I have data and sorting on server (I try to use webix.remote, but it may not be important). Is it possible to define implicit sort and filters, which are used on the first load request and showed in gui?
One close way I found is using url=webix.remote… and after render call setState(sort:, filter:); this way there are 3 requests to load function (null, sort, sort + filter), which is unnecessary and may affect performance
For now I am trying to use own proxy.
I add in datatable configuration object:
url: "remote->module.load", // filters will not be set from params
params: {
sort: {
id: "col",
dir: "asc"
},
filter: {
col: "val"
}
},
and use this proxy:
webix.proxy.remote = {
$proxy: true,
load: function (view, callback, params) {
params = webix.extend(params || {}, view.config.params);
params = webix.extend(params, {
start: 0,
count: view.config.datafetch || 100,
filter: {}
});
for (i in params.filter) {
if (view.getFilter(i)) {
view.getFilter(i).value = params.filter[i];
}
}
view.markSorting && params.sort.id && view.markSorting(params.sort.id, params.sort.dir);
var remoteFn = webix.remote;
var remoteArr = this.source.split('.');
for (var i = 0; i < remoteArr.length; i++) {
if (!remoteFn[remoteArr[i]]) {
return false;
}
remoteFn = remoteFn[remoteArr[i]];
}
console.log('proxy load ' + JSON.stringify(params));
remoteFn(params).then(function (data) {
webix.ajax.$callback(view, callback, data ? data : null);
});
return false;
}
};
If I need filters to be set, I also have to load table explicitly after render instead of by using url parameter:
this.grid.load("remote->uzivatele.load");
I think I am reinventing wheel, is there a better way?