This is a migrated thread and some comments may be shown as answers.
Adding custom attributes to nodes from client
1 Answer 74 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Luca asked on 24 Apr 2015, 10:49 AM

Hi Everyone,

I'm trying to add custom attributes to treeview nodes. I'm querying a web api 2 service trough a $.ajax call. On success event I firstly create an observable containing an observableHierarchy and then I bind it with the kendo tree view.

                            url: serviceBaseUrl + "/Arguments/GetCategoryArgumentMap",
                            success: function(data) {
                                //Gestione espansione di tutti i nodi
                                //$(data).each(function() {
                                //    this["expanded"] = true;
                                var checkedNodesNameClient = [];
                                argumentsDataSource = kendo.observable({
                                    hItem: kendo.observableHierarchy({
                                        data: data,
                                        schema: {
                                            model: {
                                                children: "Associateds",
                                                id: "ArgumentId",
                                                expanded: true
                                    checkboxes: {
                                        checkChildren: true,
                                        template: function(data) { console.log(data.item.Associateds); return "<input type='checkbox' data-mainArgument='" + data.item.Associateds.mainArgument + "' />"; }
                                    dataTextField: "ArgumentCode",
                                    check: onTreeViewItemCheck,
                                    select: onTreeviewItemSelection,
                                    dataSource: argumentsDataSource.hItem,
                                    dataBound : function () {
                                        $("#treeview > ul > li > div span.k-checkbox").hide();
                                        $("#treeview INPUT[type='checkbox']").addClass("km-widget");
                                checkTreeViewItems(viewModel.result.AssociatedArguments, $("#treeview").data("kendoTreeView"), checkedNodesNameClient)
                                $("#argumentsFilter").bind("keyup", function(){
                                    $("#treeview > UL > LI").hide(); 
                                    $("#treeview > UL > LI:contains('" + $(this).val() + "')").show();
                                $("#selectedTVItems").text(checkedNodesNameClient.join(", "));

How can I achive my target?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 28 Apr 2015, 09:27 AM

The treeview does not currently support setting attributes from the data. Could you clarify why this is needed in your case?

Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question