This is a migrated thread and some comments may be shown as answers.
treeview append always "undefined"
2 Answers 116 Views
This is a migrated thread and some comments may be shown as answers.
Wyatt
Top achievements
Rank 1
Wyatt asked on 21 Feb 2014, 08:56 PM
Below you can see the pertinent code.  when I try to append a new node in the tree it's always "undefined" when I check $("#appendNodeText").val() it does have the correct value.  What am I missing?


@(Html.Kendo().TreeView()
                    .Name("treeview")
        //.TemplateId("treeview-template")
                                .HtmlAttributes(new { @class = "col-md-6", id = "treeview" })

                    .DataTextField("Title")
                    .DataImageUrlField("Image")
                    .DataSource(dataSource => dataSource
                        .Read(read => read
                            .Action("Categories", "DisplayArticle")
                        )
                    )
                    .Events(events => events
                    .Select("onSelect")
                    )
)

    <li>
        <input id="appendNodeText" value="Node" class="k-textbox" />
        <button class="k-button" id="appendNodeToSelected">Append node</button>
    </li>




    var treeview = $("#treeview").data("kendoTreeView"),
        handleTextBox = function (callback) {
            return function (e) {
                if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
                    callback(e);
                }
            };
        };


        var append = handleTextBox(function (e) {
            //var treeview = $("#treeview").data("kendoTreeView")
            var selectedNode = treeview.select();

            // passing a falsy value as the second append() parameter
            // will append the new node to the root group
            if (selectedNode.length == 0) {
                selectedNode = null;
            }
            
            treeview.append({
                Name: $("#appendNodeText").val(),
                id: $("#appendNodeText").val(),
                text: $("#appendNodeText").val()
            }, selectedNode);
        });

        $("#appendNodeToSelected").click(append);

2 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 25 Feb 2014, 08:32 AM
Hello Wyatt,

The TreeView is configured to use the Title field (through the DataTextField("Title") invocation). Thus, when appending items, you should specify that field instead of the default one (text). 

    treeview.append({
       Title: $("#appendNodeText").val()
    }, selectedNode);


Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ali
Top achievements
Rank 1
answered on 31 May 2015, 06:56 PM
i used name property instead of text or title
and worked
 treeview.append({

            Name: nodeText,

            id: nodeValue

        }, selectedNode);
Asked by
Wyatt
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
ali
Top achievements
Rank 1
Share this question
or