Erik T.
Erik T.

Reputation: 370

Kendo UI - Get text of a treeview node

I have a problem with the Kendo UI TreeView and I'm looking for a solution for a while now. I found something similar here, but it didn't help me.

In my view I fill my TreeView like this:

Html.Kendo().TreeView()
                    .Name("treeview")
                    .BindTo((IEnumerable<TreeViewItemModel>) ViewBag.inlineDefault)
                    .Events(events => events
                        .Select("onSelect")
 )

private IEnumerable<TreeViewItemModel> GetDefaultInlineData(ArrayList tables)
        {
            List<TreeViewItemModel> names = tables.Cast<TreeViewItemModel>().ToList();

            List<TreeViewItemModel> inlineDefault = new List<TreeViewItemModel>
            {
                    new TreeViewItemModel
                    {
                        Text = "Tables",
                        Items = names
                    }
            };

            return inlineDefault;
        }

My onSelect funtion is the following:

<script>
    function onSelect(e) {
        $.ajax({
            type: 'POST',
            url: '/Editor/GetTableContent' ,
            data: { tableName: ?????? },
            success: function (data) {
                $('#table').html(data);
            }
        }).done(function () {
            alert('Done');
        });
    }
</script>

It calls a mehtod in my controller that needs the name of the selected node as parameter (string) to display the content of a table in a grid.

Is there a possibility to get what I need?

Thx for your help!

Upvotes: 0

Views: 743

Answers (1)

The Dread Pirate Stephen
The Dread Pirate Stephen

Reputation: 3169

To get the text of the selected node in onSelect():

var nodeText = this.text(e.node);

this == the TreeView(can also use e.sender instead of this)

e.node == the selected node.

http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#events-select

http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#methods-text

Upvotes: 1

Related Questions