This is a migrated thread and some comments may be shown as answers.

Set value and other attributes when adding node

5 Answers 516 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 05 Jul 2012, 07:42 AM
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

5 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 05 Jul 2012, 03:07 PM
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!
0
Victor
Top achievements
Rank 1
answered on 05 Jul 2012, 07:05 PM
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
0
Accepted
Petur Subev
Telerik team
answered on 09 Jul 2012, 09:00 AM
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!
0
Victor
Top achievements
Rank 1
answered on 09 Jul 2012, 10:28 AM
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
0
Accepted
Petur Subev
Telerik team
answered on 28 Nov 2012, 09:36 AM
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!
Tags
TreeView
Asked by
Victor
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Victor
Top achievements
Rank 1
Share this question
or