how to dynamically define the url & save properties

I need load different database/tables depending on each user is loged in. I have tried the most obvious options but unsucessfully. I tried to modify the view object property url/save at onBeforeLoad event. I used onBeforeLoad inline, because it does not fires when attached externally. Below one of the options:

onBeforeLoad: function(id){
var acc = localStorage.getItem('_account');
var account = JSON.parse(acc);
$$("datatree1").define("url", "php/wpt" + account.path + "_datatree.php");
$$("datatree1").define("save", "connector->php/wpt" + account.path + "_datatree.php");
$$('datatree1').refresh();
return true;
}

Comments

  • onBeforeLoad isn't needed in such case.

    For data loading, please use

    $$("datatree1").clearAll();
    $$("datatree1").load("php/wpt" + account.path + "_datatree.php"); 
    

    save property also cannot be redefined. But the same can be done through the ajax helper.

  • Thanks Listopad. However I am wishing I have missunderstood your answer.
    One of the most powerfull features of webix is its data connector/processor ability to load/update data from components to/from database transparently. I realy would not like to loose this facility at last in this stage of evaluating the webix lib. Please let me remake my question in other words, so I could get a most favorable answer: " A treetable needs load/save its data from a database table which is working fine. But sometimes, a copy of this database table needs to be pointed to for load/save, but this copy is located on a different folder/diretory". How may I do it ?

  • There's another way. If you're using a data connector/processor, theurl transforms into an object with the source property. Therefore, an url can be redefined as

    datatable.config.url.source = "new_url";
    

    As forsave link, you can get and change it through the DataProcessor:

    webix.dp(datatable).config.url.source = "new_save_url";
    
  • Thanks...work fine now. If we could find a way to execute code with the replacing paths during initialization of component would be even better. This way, should be possible to automatically open the last path/file the user was working with. If not, no problem I will try with cookie or something else. :)

  • edited June 2016

    If we could find a way to execute code with the replacing paths during initialization of component would be even better.

    You can extend the component with help of protoUI, and in the constructor of a new component place a logic, which will set the necessary url and save values.

  • For save I had to use:
    webix.dp(datatable).config.url = "new_save_url";

    Without .source

  • edited January 11

    Hi,

    webix.dp(datatable).config.url = "save.php";

    Does using the above solution break events onAfterUpdate functionality?

    Mainly, the problem is the response JSON is not recognized. Therefore I am having problems passing the record id for simultaneous update after datatable row is inserted.

    Has there been any other solutions since to dynamically define save url?

  • Changing url of dataprocessor object must not break anything

    As more advanced pattern it possible to create a proxy object which will handle saving https://docs.webix.com/desktop__server_proxy.html#creatingcustomproxyobjects

    Mainly, the problem is the response JSON is not recognized

    May be not related to url change. Check the status code of response ( it must be below 400, or result will be processed as an error ) Also, webix uses strict json parsing rules, so be sure that all JSON keys are wrapped in doublequotes.

  • edited January 14

    I experimented not changing the url and the onAfterUpdate will fire successfully. The update also correctly reads the new id passed from the JSON response. Only after using webix.dp(datatable).config.url = "save.php"; does it stop working, though no errors are thrown. I can only guess that this config overwrites or resets the save options that were originally set.

    I only needed this to pass a variable to the save url i.e. webix.dp(datatable).config.url = "save.php?option=XXX";, but I figured out a way to just pass this variable with a hidden column. Will look into the proxy objects.

Sign In or Register to comment.