Set value and other attributes when adding node

6 posts, 2 answers
  1. Victor
    Victor avatar
    167 posts
    Member since:
    Nov 2010

    Posted 05 Jul 2012 Link to this post

    Hi,
    A bit similair to this other thread we wonder how to set the value attribute when appeding new nodes. Right now we do this:
    treeview.append({
    text: "New text",
    value: "Value",
    url: "/dummyUrl"
    });

    The node is added, with the correct text. The link is added, but value is not. (Also the attribute k-link is not added even when it is a link). Similair to the other poster it would also be nice to know if there is another way than manually via jQuery to get the value.

    Thank!
    /Victor
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 05 Jul 2012 Link to this post

    Hi Victor,

    I am afraid that the kendo TreeView currently does not support its items to have values in contrast to the MVC TreeView. I am sorry for the inconvenience.

    Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Victor
    Victor avatar
    167 posts
    Member since:
    Nov 2010

    Posted 05 Jul 2012 Link to this post

    Hmm... I see... They are supported in the server wrappers though:
    .Items(treeview =>
                        {
                            treeview.Add().Text("Text").Value("Value");
                        })

    (renders a hidden input element with the value set)

    They are not supported in the client api though you mean? If not, is there any other data-store that is available in both the server wrappers and the api?


    Thanks
    /Victor
  5. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 09 Jul 2012 Link to this post

    Hello Victor,

    Yes I am afraid that currently there is no client side API method which allows you to get the value for an item if it is set on the server with the Value method. However if your TreeView is bound via a dataSource, you could get the whole dataItem via the dataItem method. Please check this Beta demo for more information.


    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Victor
    Victor avatar
    167 posts
    Member since:
    Nov 2010

    Posted 09 Jul 2012 Link to this post

    Hi and thank you for your reply!

    We will look into the dataItem method and the possibilities. For now we add the missing classes as well as an input tag for the value via javascript after the node is added via the api and get the value from the input value via custom code as well. We will however look up the dataItem method as an alternative. Thanks for clearing up the options available!

    /Victor
  7. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 28 Nov 2012 Link to this post

    Hello,

    To sum things up (current official version Q3 2012) when using the MVC TreeView wrapper:
    • If the TreeView is populated initially on the server via the Items method or the BindTo method you can only retrieve the Text or the Id fields when using the dataItem method of the client API (rest of the fields are not serialized and they are not available on the client).
    • If you are using Ajax Binding you will be able to retrieve the whole model (all of its fields) with the dataItem method.

      For example if you return the following from the Controller:

      public JsonResult Employees(int? id)
      {
          var dataContext = new NorthwindDataContext();
       
          var employees = from e in dataContext.Employees
                          where (id.HasValue ? e.ReportsTo == id : e.ReportsTo == null)
                          select new {
                              id = e.EmployeeID,
                              Name = e.FirstName + " " + e.LastName,
                              Foo="someValue",
                              Bar="otherValue",
                              hasChildren = e.Employees.Any()
                          };
       
          return Json(employees, JsonRequestBehavior.AllowGet);
      }

      Then the Foo and the Bar properties will be serialized too and they will be available in the JavaScript object returned from the dataItem method.

    Kind regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready