How to programmatically navigate to certain path in File Manager?

Our goal is to programmatically drill down to certain path on initial load of the File Manager. For example, we are given /Folder A/Folder B/Folder C, and we need to navigate to Folder C automatically

We attempted couple API functions, but none of them really worked out for us:

  • Tried openFolders, and it worked okay, but only for left side File Tree folders were opened. Nothing happened on main view
  • Tried setPath, but it worked only for immediate child folder. In our case, it just opened Folder A. I also tried to open Folder B, whenever loading of Folder A completes via onPathComplete, but it didn’t work. Nothing happened when I called setPath('/Folder A/Folder B')
  • Tried loadBranch loads data, but as description implies it only works for direct child and this data needs to be injected into a view
    loads data to the specified branch, as direct children of the node with the ID provided

Hello @olzhas,

Our goal is to programmatically drill down to certain path on initial load of the File Manager

The best way to achieve the expected result would be to use the setPath() method. Judging from your post, it doesn’t seem to be working as inteded in your case. I’ll try to go over why this might be the case.

Tried openFolders, and it worked okay, but only for left side File Tree folders were opened

That is essentially the main purpose of this function, to actually navigate to a certain folder, please refer to the setPath() method (this method actually invokes the openFolders() method as well).

Tried setPath, but it worked only for immediate child folder

This is rather strange, as the setPath() method should work just fine (in the case of dynamic loading too). That said, there is a specific case in which this method will actually fail every time - that is, if your item ids contain a slash symbol /. For example, your id could look like this: /Data/sub1. As you call the setPath() method, the provided string will be processed in a way that removes the slashes, making the further references wrong (basically, the outcoming ids will be incorrect).

Could you please specify if your dataset contains ids with a slash in them, or is that not case? Provided that the ids don’t contain any slashes, the setPath() method should work just fine (tested locally using branch/files modes).

Hi @Dzmitry,

Thanks for reply. Yes we do use forward slashes in our ids like it was shown in issue description. I though it’s normal to have slashes in the ids since most of the sample snippets provided by Webix use slashes in the ids.

How should we handle slashes in the id’s? Here’s the snippet:

https://snippet.webix.com/fs4gebw0

I though it’s normal to have slashes in the ids since most of the sample snippets provided by Webix use slashes in the ids.

The unfortunate reality here is, our backend doesn’t handle the setPath() method properly as well (precisely because of the slashes in the ids).

Basically, the setPath() method expects you to provide a full path to the specified folder. Since the full path will also contain slashes, the logic gets broken in the case where ids have a forward slash in them. This is only true in the case of a dynamic loading, as there is no way to get the target id from the data (since we don’t have the corresponding data on the client yet). The setPath() method employs a different algorithm in the case of a dynamic loading - the provided path with forward slashes gets split based on where these slashes are place. So, essentially, the /Data/sub2 path becomes ["Data", "Data/sub2"], which is obviously incorrect in this case (the setPath method invokes the openFolders method, which requires a correct array of ids to proceed with the rest of the logic).

The main culprit here is the very first slash in the first id, which breaks the method entirely. Unfortunately, it is not possible to rewrite the method responsible for forming the path, as it is contained within the private logic. The only proper way to solve the issue is to modify the id on the very top level in a way that makes it not contain any slashes at all.