Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've just found Dynatree and I'm using it on my MVC project. Here's an example of how I did it. I decided to just put the data directly in the View like the <a href="http://wwwendt.de/tech/dynatree/doc/sample-default.html#" rel="nofollow noreferrer">basic example</a>.</p> <p>My data is a list of cities within California, grouped by county.</p> <p>My controller simply passes a view model to my View and the view model has a CitiesAvailable property:</p> <pre><code>public IEnumerable&lt;City&gt; CitiesAvailable { get; set; } </code></pre> <p>My list of City objects is grabbed from the database (EF4) and the actual City object is the following:</p> <p><img src="https://i.stack.imgur.com/yFmOS.png" alt="CityObject"> </p> <p>In my View I create a ul containing the list of counties and their cities (I'm using Razor but webforms should be easy enough to figure out):</p> <pre><code>&lt;div id="tree"&gt; &lt;ul id="treedata" style="display: none;"&gt; @foreach (var county in Model.CitiesAvailable.Select(c =&gt; c.County).Distinct().OrderBy(c =&gt; c)) { &lt;li data="icon: 'false'"&gt;@county &lt;ul&gt; @foreach (var city in Model.CitiesAvailable.Where(c =&gt; c.County == county).OrderBy(c =&gt; c.Name)) { &lt;li data="icon: 'false'" id="@city.Id"&gt;@city.Name&lt;/li&gt; } &lt;/ul&gt; &lt;/li&gt; } &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Then in my JavaScript I use the following:</p> <pre><code>$("#tree").dynatree({ checkbox: true, selectMode: 3, fx: { height: "toggle", duration: 200 } }); </code></pre> <p>It works great! Here's a sample of the output with a few items checked:</p> <p><img src="https://i.stack.imgur.com/QfX4d.png" alt="Screenshot of Dynatree result"></p> <p>Let me know if anything doesn't make sense.</p> <p>Note, I use data="icon: 'false'" in my li elements because I don't want the icons.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload