grid.sync(data) event handling

Hi at all, i’m working with webixjet and i’m working with models.
I have some difficuties with handling events after loading data into a datatable.

I use a model because I need to send some parameters to the get call, so i cannot use the property “url” of the datatable but I need lo load data after a custom ajax call.
But there is no way to create a callback after populating a datatable using the sync method!
No callback or events to attach to.

And there are no other method to populate a datatable using model.

Am I wrong?

Thank you

https://docs.webix.com/api__link__ui.datatable_url_config.html
you can use any kind of parameters using proxy as url

{
    view:"datatable",
    url:{
        $proxy:true,
        load:function(view, params){
            return webix.ajax().get("load.php", params);
        }
    }
}

or using function as url

{ view:"datatable", id:"table", autoConfig:true, url:function(params){
    return webix.ajax("some/path");
}};

there is waitData promise object which you can use for first time data loading.
also you can use onSyncApply event of DataStore

table.data.attachEvent("onSyncApply", function(){
    ...
});

Thanks for your reply @integral .
Ok this part is clear, and now I can call the “load” method after filling a form.

But how to work with model?
The only way to work with a model that returns a DataCollection, is the sync method.
But the onSyncApply does not have all the specific temporal events of the load: onbeforeload, onafterload, onLoadError and also onValidationError, onValidationSuccess…
Thats because you cannot “load” from a model, even if you return a promise object.

Yesterday I saw also that the “schema” is also a property of the DataTable (I guess because it implicitly creates a DataCollection when data has been loadedto into), so I moved the “schema” property from my model to the DataTable configuration.

In this scenario models are useless… I cannot see any advantage using models in webix.
Maybe with small collections that does not require to be loaded frequently or dynamically (after a search), and can be cached and returned into an instance.
(Think for example to a list of cities…)

What do you think about?

it is hard to say something without snippet.
if you have datacollection model as data source and want to ensure that it is loaded before sync, you can you datacollection’s waitData promise and do sync when it is ready

import collection from "model";

{
    init(view){
        collection.waitData.then(()=>{
            ...pre-sync operations...
            $$("table").data.sync(collection);
            ...post-sync operations...
        )
    }
}