Treeview -how to decleratively set the active -selected item


Topic: Treeview -how to decleratively set the active -selected item

Yiannis Kyriazidis asked 3 years ago

How can we set the active item in the list of items ? So that when the treeview is rendered the specific list item is expanded and focused (as if user clicked on it) I tried setting the active class on the list item but did'nt work.

Example https://mdbootstrap.com/snippets/standard/yiannis_kyriazidis/3285521


thank you. I am using this in a sidebar menu and I know the li element of the link, but not the parent ul. Can you please adjust the example so based on an li element that has a class equal to class= 'active" the javascript wIll find the parent ul and attach an id to it so i can then call the javascript method you have created so that the parent is expanded and the selected li element is active ? Thank you .


Michał Duszak staff commented 3 years ago

I have prepared a snippet in which, on a button call, the script looks for a li with class equal to class='active'. Then it assigns it an ID required for expand() method. Then it expands, and then it removes the ID since it's no longer neccessary. It looks for the closest parent to expand it, so I believe it pretty much needs your requirements. What do you think?

https://mdbootstrap.com/snippets/standard/m-duszak/3288178#html-tab-view


Michał Duszak staff answered 3 years ago

You can expand your treeview to the particular list using the expand(ID) method.

https://mdbootstrap.com/snippets/standard/m-duszak/3286199#html-tab-view


what does the treeview.filter method do ? maybe that can be used to set a custom condition and expand to the list item that has class="active" ?

eg

expandInstance.filter ('.active');


Michał Duszak staff commented 3 years ago

It works like a search. It will expand list basing on the content of the li element https://mdbootstrap.com/snippets/standard/m-duszak/3288276


Yiannis Kyriazidis commented 3 years ago

thanks . good to know.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.9.0
  • Device: windows desktop
  • Browser: chrome
  • OS: windows
  • Provided sample code: No
  • Provided link: Yes
Tags