datatable server implicit sort + filter

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?

The simplest solution will be to extend datatable, and apply the sorting and filtering before setting the url.

webix.protoUI({
    name:"mytable",

    $init:function(config){
         this.$ready.push(function(){
            if (config.params){
                 // there is no url and no data, so you can set sort and filter as necessary
                 // or just use setState here, as it will not cause data loading anyway
                 this.markSorting(...
                 this.getFilter(...
                 //load initial data 
                 this.config.url = config.params.url;
                 this.loadNext();
            }
         }
    }
}, webix.ui.datatable);

now the widget can be used like next

webix.ui({
  view:"mytable", 
  params:{
         url:"some", sort, filter
  }
})

If you want to do the same without creating a new UI, you can use

webix.ui({
   id:"t",
   view:"datatable"
});

$$("t").setState(filter_sort_etc)
$$("t").config.url = my_url;
$$("t").loadNext(); //trigger data loading will filter and sort applied

Hi, I’'m trying to set search params on my data table object - found this article - have tried this:

$$(“ticketsMainViewId”).setState({sort: ‘asc’, status: ‘WIP’});
$$(“ticketsMainViewId”).load("/sapi/tickets/" + id + “/0/0”);

Nothing is happening. Do I have to pass the additional GET params as part of the URI request? /sapi/tickets/1/2/3?sort=asc&status=WIP