How to keep TreeView expanded when the page is loading.

Hi,
I need to make all the TreeView nodes to be expanded when my web page is loading. My code for TreeView is down there.

@(Html.EJ().TreeView("BUTree")
                                .TreeViewFields(field =>
                                    field.Datasource((IEnumerable<object>)ViewBag.griddata)
                                    .Id("BUKey")
                                    .ParentId("PrntBUKey")
                                    .Text("BUName")
                                   .Expanded("expanded")

                                )
    )

But it doesnt get expanded when loading. How do I get this behaviour. Please help.

Thank you
Kalum

3 Replies

AB Ashokkumar Balasubramanian Syncfusion Team July 5, 2018 08:59 AM UTC

Hi Kalum, 
 
We have checked your reported problem with your provided code block. We suspect that you may missed to define the Expanded mapping field values in data source. Could you please ensure this at your end? 
 
[Model] 
 
public class TreeModel 
        { 
            public int BUKey { get; set; } 
            public int PrntBUKey { get; set; } 
            public string BUName { get; set; } 
            public bool expanded { get; set; } 
        } 
 
[DataSource] 
 
List<TreeModel> griddata = new List<TreeModel>(); 
griddata.Add(new TreeModel { BUKey = 1, PrntBUKey = 0, BUName = "Item 1", expanded = true }); 
griddata.Add(new TreeModel { BUKey = 2, PrntBUKey = 0, BUName = "Item 2", expanded = true }); 
 
For your requirement, we have prepared a sample, please find the sample in below location. 
 
Sample Link:  
 
 
To know more details about Populate data in TreeView component, please check the following help document. 
 
 
Please let us know, if the provided information’s are helpful to resolve your problem or not. 
 
Regards, 
Ashokkumar B. 



KA kalum July 5, 2018 05:14 PM UTC

Hi Ashokkumar,
I could solve my problem according to your answer and you are correct, I have missed to define the Expanded mapping field values in data source.
Thank you very much for your kind help.
Kalum



AB Ashokkumar Balasubramanian Syncfusion Team July 6, 2018 05:47 AM UTC

Hi Kalum, 
 
Most Welcome. 
 
Please let us know, if you need any further assistance on this. 
 
Regards, 
Ashokkumar B. 


Loader.
Up arrow icon