How to modify query sent to server on datatable filtering

Hello,

I am trying to find the best solution to modify the query sent to the server before filtering/requesting data from the server on a datatable component. The same should apply for dataview and other components.

I figured out that modifying the passed parameters on ‘save’ is straightforward:

onBeforeUpdate:function(id, o) {
o.data.newVariable = newValue;
}

and I can add up any number of fields in the post request.

When retrieving data though, that is not so clear on were to access the data to be used in the query. An approach will be with registerFilter but I believe this requires creation on a dummy column.

I have figured that I can do that easy with:

onBeforeFilter: function() {
this.data.url = “script.php?field=value”;
}

and webix takes care to keep my query string in tact and append to it the rest of the filter params.

What would be the most proper way to do this? Is there any other way to access and modify the data in the query before filtering?

Please share your thoughts.

a) Insert|update|delete - if you are using default data saving logic, you can assign your code to events of dataprocessor

var dp = webix.dp($$("datatable"));
dp.attachEvent("onBeforeDataSend", function(send){
  send.data.some = 123;
});

It will alter only the data which will be sent to the server side and will not alter data objects.

http://docs.webix.com/api__dataprocessor_onbeforedatasend_event.html

b) Data loading

There are few different solution. You can modify data url from onBeforeFilter handler, that is valid approach, but I think using Data Proxy is the better one

webix.ui({
   view:"list",
   url:{
       proxy:true,
       load:function(view, callback, state){
               //this code will be used for all data loading calls
               //state - filters, and sorting states
                webix.ajax("some.php", callback, view);
       }
   }
})
webix.ajax(this.source, callback, view);

http://docs.webix.com/desktop__server_proxy.html#creatingcustomproxyobjects

Proxy can be used for data saving, as well

And as ultimate solution, you can use onBeforeAjax event, that allows to intercept and alter any AJAX call

http://docs.webix.com/desktop__server_customload.html#modifyingbackgroundajaxrequests

Thanks maksim,

onBeforeFilter worked for me. Wanted to make sure it is the proper way to use a query string in the url such as ajax.php?key=value.