iVantage / angular-ivh-treeview

A treeview for AngularJS with filtering and checkbox support.
http://ivantage.github.io/angular-ivh-treeview/
MIT License
238 stars 89 forks source link

How to show "No results" message #192

Open ahmed-abdulmoniem opened 7 years ago

ahmed-abdulmoniem commented 7 years ago

Hi,

If after the filter is applied to the nodes, there are no nodes are shown I want to - instead of just empty div or panel - show a message "No results".

Is that possible?

Thanks.

jtrussell commented 7 years ago

There's no explicit option to set this but you may implement it as part of your template.

In your template you have access to depth, trw.root() and trvw.isVisible(node). You may show your "No results" message if none of the root notes are visible (trvw.root() may return a single node or an array of nodes depending on how you set up your treeview). depth may just be handy so you aren't performing too many redundant is there data? checks.

ahmed-abdulmoniem commented 7 years ago

How can I access depth? Is there any doc on how to use trvw?

jtrussell commented 7 years ago

Yep, this section of the docs talks about the scope variables provided to your template and how to use them: https://github.com/iVantage/angular-ivh-treeview/blob/master/docs/templates-and-skins.md#supported-template-scope-variables

ahmed-abdulmoniem commented 7 years ago

Thanks.

OK the problem now is that I am showing a list of nodes without any parent node .. just a list of nodes representing a list of categories.

How can I achieve "No results" message then?

jtrussell commented 7 years ago

trvw.root() should give you that array of top level categories. I'd probably create a small "No results" directive and pass it whatever trvw.root() spits out (+ depth or something). The no results directive could display text if none of the categories are visible.

If that's not very clear I'd be happy to take a look at some code but would you mind posting on Stack Overflow? You can drop a link here to the SO question here.

ahmed-abdulmoniem commented 7 years ago

Sorry I don't get you.

When I use trvw.root().length I always get 20 = number of categories even if there is no one shown in the list!

jtrussell commented 7 years ago

The nodes are always there just not always visible. You'll want to filter that list using trvw.isVisible.

ahmed-abdulmoniem commented 7 years ago

ah! OK I will check then and get back to you.

ahmed-abdulmoniem commented 7 years ago

Can I use this trvw.isVisible(Object node) inside a .js file not in the template?

ahmed-abdulmoniem commented 7 years ago

Also, using template doesn't help because it is a template of each node and I want to show the message only one time per the whole tree not under each node. And when the nodes are not visible nothing will be shown!