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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TreeGrid | Dynamic columns possibilities

Thread ID:





123239 Feb 29,2016 12:01 PM UTC Mar 1,2016 11:56 AM UTC ASP.NET MVC 1
Tags: TreeGrid
Martin R
Asked On February 29, 2016 12:01 PM UTC


after brief exploration of examples and documentation I figured out that Tree Grid in ASP.NET MVC (not WPF) can be rendered only by specifying exact (static columns) defined in some class (eg. viewModel).

For example including this in Razor page:

             .Columns(co =>
                   if (ViewBag.treeGridDataSource != null)
                       co.Field("TaskId").HeaderText("Task Id").Width(45).Add();
                   co.Field("TaskName").HeaderText("Task Name").Add();
                   co.Field("StartDate").HeaderText("Start Date").Add();
                   co.Field("EndDate").HeaderText("End Date").Add();
             .SizeSettings(ss => ss.Width("100%").Height("600px"))
However I want to render columns dynamically according to user settings. Not only hide or show specific (earlier specified, hard typed) columns. For example I want to write something like foreach(var ViewBag.ColumnList){ co.Field("ColumnListItem.Name").HeaderText("ColumnListItem.HeaderText").Add(); }

Is it somehow possible to generate dynamic columns in Tree Grid for ASP.NET MVC?

Thanks all,
Martin Rasovsky

Mahalakshmi Karthikeyan [Syncfusion]
Replied On March 1, 2016 11:56 AM UTC

Hi Martin,

Thanks for contacting Syncfusion support.

We can render dynamic columns based on the conditions in ASP.Net MVC TreeGrid as you have done in your code example. Please refer the below code example for details.



.Columns(co =>


                   if (ViewBag.dataSource == null)


                       co.Field("Id").HeaderText("Task Id").Width(45).Add();


                   co.Field("Name").HeaderText("Task Name").Add();

                   co.Field("StartDate").HeaderText("Start Date").Add();







We have also prepared a sample based on this and you can find the sample under the following location.

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/DynamicColumn2079197477

Note: We have removed bin and obj folder in the given sample for some security reasons, we must include Syncfusion.EJ and Syncfusion.EJ.MVC dlls to render the TreeGrid control which is available in Essential studio installed location


Mahalakshmi K.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon