Ticket T973382
Visible to All Users

TreeView - How to get parents of selected nodes

created 4 years ago

Hi DevExpress,

I am just using the DropDown Treeview control and my company is very impressed on how rich the functionality is - brilliant work. I just have a query. I am just trying to get the name of the parent node selected. I am using the getSelectedNodes function but cannot get the selected parent name(Category Name) e.g. "Promise To Pay". Any clues ?

View
@(Html.DevExtreme().TreeView()
.DataSource(new JS(@"component.getDataSource()"))
.ID("statusTreeView")
.KeyExpr("ID")
.DisplayExpr("Text")
.ItemsExpr("Items")
.ExpandedExpr("Expanded")
.ParentIdExpr("CategoryId")
.DataStructure(TreeViewDataStructure.Plain)
.SelectionMode(NavSelectionMode.Single)
.SelectByClick(true)
.Height(235)
.OnItemSelectionChanged(@<text>

JavaScript to display the selected values

var selected = treeView.getSelectedNodes()
.map(function (node) { return node.itemData; });

if (selected.length) {

if (selected[0].CategoryId) {

console.log(selected);

Kind Regards
Akshay

Answers

created 4 years ago

Hello,

TreeView Nodes contain the parent option, which contains the parent of the Node. For example:

JavaScript
var selected = treeView.getSelectedNodes() .map(function (node) { return node.parent; });

Could you please clarify if this is what you are looking for? This will help us give you a more precise response.

    Comments (2)
    AK AK
    Akshay Khurana 4 years ago

      Perfect, I used this. Many thanks

      var selectedParent = treeView.getSelectedNodes()
      .map(function (node) { return node.parent; });

      var parentValue = selectedParent[0].text;

      DevExpress Support Team 4 years ago

        Hello,

        You are welcome. I am happy that you also found a solution. If you have questions or need further assistance, please feel free to contact us.

        Regards,
        Angelo

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.