filemanager load data dynamically usign files method - and append folder data

edited November 2019 in Technical questions

Hello. I'm using Webix filemanager and I'm trying to load data on it dynamically.
I managed to show root data using load

$$("gallery-structure").load({
  $proxy: true,
  load: function (view, params) {
    return Images.getImagesRootStructure(true).then(function (response) {
      var d = new Array();
      d[0] = response.data;
      return d;
    });
  }
});

But when I select wanted folder - I don't know how to attach/append received data to filemanager.

***Handler
handlers: {
  "files": loadFolder
},
***
var loadFolder = {
  $proxy: true,
  load: function (view, callback, params) {

    return Images.getImagesFolderStructure(folderName, level).then(function (response) {

      //I have data here , what should I do with it
      if (response.data) {
        return response;
      }
    });
  }
};

Comments

  • edited November 2019

    Hello @mtasic,

    But when I select wanted folder - I don't know how to attach/append received data to filemanager.

    The data will be "appended" automatically, as long as the response follows the expected format. The load() method needs to return the URL request with the correct query parameters (you don't need to handle the result of the promise, it will be handled accordingly by the filemanager). Please refer to the following article to learn the correct way to handle dynamic loading in "files" mode. While it doesn't include an example using a custom proxy, the principle stays the same.

    load: function (view, callback, params)
    

    I am not quite sure about the version you are using, but I thought it was worth mentioning - please note that if you are using Webix 6.2 and above, the arguments received by the load() method (as well as all of the other proxy method) are a bit different, and don't include the callback anymore.

    Here is an approximate example using a custom proxy in "files" mode: https://snippet.webix.com/nl8phldm (try loading the "newFolder" folder located in the root directory - you will see that a new folder is loaded dynamically, if it doesn't exist - simply create that folder in the root directory and follow the path). Unfortunately, this example i fairly static, as I am not able to provide a custom backend that would react accordingly to the changes we've made.

  • edited November 2019

    We are using version 6.2 . I will update to latest version. I figured it out - i just wrapped out the response to

    return Images.getImagesFolderStructure(folderid, folderName, level).then(function (response) {
      if (response.data) {
    
        var res = {
          parent: folderid,
          data: response.data.data
        };
    
        return res;
      }
    });
    

    so it have correct parent.

  • load: function (view, callback, params) - in my case callback were params , params is undefined. Thanks for that

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!