We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add Feature to handle Guid.Empty as root node

The current TreeView (and maybe some other control?) is looking for the root node to have a parentId value to be null. However, if we are using GUID's for our Id and ParentId the TreeView doesn't work. Can you please add this feature in the next release? 

Sure, we can convert the Guid to a string but adding this feature would be value add to your customers :)

VR Architect

3 Replies

SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team January 13, 2020 09:54 AM UTC

Hi Scott, 
 
We have checked your reported query that GUID is not working in TreeView component. We are unable to reproduce the issue in our end.  
 
We have prepared a simple sample using GUID for id and parent id in TreeView component. Refer the below code snippet. 

<EjsTreeView TValue="MailItem"> 
    <TreeViewFieldsSettings TValue="MailItem" Id="Id" DataSource="@MyFolder" Text="FolderName" ParentID="ParentId" HasChildren="HasSubFolders" Expanded="Expanded"></TreeViewFieldsSettings> 
</EjsTreeView> 
 
 
public class MailItem 
    { 
        public Guid Id { get; set; } 
        public Guid? ParentId { get; set; } 
        public string FolderName { get; set; } 
        public bool Expanded { get; set; } 
        public bool HasSubFolders { get; set; } 
    } 
    List<MailItem> MyFolder = new List<MailItem>(); 
    protected override void OnInitialized() 
    { 
        base.OnInitialized(); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247482"), 
            FolderName = "Inbox", 
            HasSubFolders = true, 
            Expanded = true 
        }); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247483"), 
            ParentId = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247482"), 
            FolderName = "Categories", 
            Expanded = true, 
            HasSubFolders = true 
        }); 
     } 


Refer the sample link below. 
 
Could you please share the details about the EJ2 controls which you are facing the same issue? We will check the issue from our end and update you further the details on it. 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Shameer Ali Baig S. 



SP Scott Peal January 15, 2020 10:08 PM UTC

Your code didn't address my request. In your sample code set ParentId  = Guid.Empty  which is how the data looks in our SQL database. The default in our SQL column is NEWID. 

What we have to do with the current Syncfusion control is to replace any Guid.Empty with a null to make it work in the control.


SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team January 17, 2020 11:59 AM UTC

Hi Scott, 
 
Thanks for the update. 
 
We have provided the support for root node to have id with “0” for the TreeView component. So, we have identified the root node by null value of parentId property for self-referential data source. So, for your requirement, we are unable to set the Guid empty value (“00000000-0000-0000-0000-000000000000”) to root node of TreeView component. However, you can achieve your requirement by using the below code otherwise you can use hierarchical type data.  
 
Refer the below code block. 
 
protected override void OnInitialized() 
    { 
        base.OnInitialized(); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247482"), 
            ParentId = new Guid(), 
            FolderName = "Inbox", 
            HasSubFolders = true, 
            Expanded = true 
        }); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247483"), 
            ParentId = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247482"), 
            FolderName = "Categories", 
            Expanded = true, 
            HasSubFolders = true 
        }); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247484"), 
            ParentId = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247483"), 
            FolderName = "Primary" 
        }); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247485"), 
            ParentId = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247483"), 
            FolderName = "Social" 
        }); 
        MyFolder.Add(new MailItem 
        { 
            Id = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247486"), 
            ParentId = new Guid("9245fe4a-d402-451c-b9ed-9c1a04247483"), 
            FolderName = "Promotions" 
        }); 
 
        for(var i=0; i<MyFolder.Count; i++) 
        { 
            if(MyFolder[i].ParentId == new Guid()) 
            { 
                MyFolder[i].ParentId = null; 
            } 
        } 
    } 
 
Refer the below link to know about hierarchical data binding for TreeView. 
 
 
Please let us know, if you need any further assistance on this. 
 
Regards, 
Shameer Ali Baig S. 


Loader.
Up arrow icon