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

Dynamically add columns

Thread ID:





127021 Oct 21,2016 08:59 AM UTC Oct 24,2016 11:03 AM UTC ASP.NET MVC 1
Tags: Grid
Jason Underhill
Asked On October 21, 2016 08:59 AM UTC

Good Morning,

I'm using the sync fusion MVC grid in an application I'm working on and there is some functionality I need to implement which I'm struggling with so I;m hoping someone might be able to point me in the right direction.

I have a result set for a report which I want to display in the sync fusion grid. It has some basic properties, Name, Email etc. But also each record has a collection of 'Breakdowns'. All of the records in the result set will have the same number of breakdowns however the number of breakdowns can change depending on the search criteria the user enters.

I have the grid generating the correct columns however as you can see below I'm using the first result's data for the breakdowns for every row which obviously isn't correct.

The code in my view is as follow:
                      .Locale("en-GB").AllowScrolling(true).ScrollSettings(col => { col.Height(450); }).MinWidth(905).EnableAltRow()
                      .IsResponsive(true).AllowResizing().AllowResizeToFit().ClientSideEvents(e => e.RowSelected("row_clicked"))
                      .Columns(col =>
                          col.Field(f => f.RecordUrl).HeaderText("RecordUrl").Visible(false).CssClass("RecordUrl");
                          col.Field(f => f.Title).HeaderText("Title").Add();
                          col.Field(f => f.FirstName).HeaderText("First Name").Add();
                          col.Field(f => f.MI).HeaderText("MI").Add();
                          col.Field(f => f.LastName).HeaderText("Last Name").Add();
                          col.Field(f => f.Email).HeaderText("Email").Add();
                          col.Field(f => f.DoctorType).HeaderText("Doctor Type").Add();
                          Model.Results.Results.First().Breakdowns.ForEach((b) => //todo: This is using the first result for every row

Just so you can see what I'm working with the classes that the results are based on are stored as follows:

public class AppraisalSummary
        public Guid Id { getset; }
        public string RecordUrl { getset; }
        public string Title { getset; }
        public string FirstName { getset; }
        public string MI { getset; }
        public string LastName { getset; }
        public string Email { getset; }
        public string DoctorType { getset; }
        public List<AppraisalSummaryTypeBreakdown> Breakdowns { getset; }

public class AppraisalSummaryTypeBreakdown    {        public Guid? TypeId { getset; }        public string TypeName { getset; }        public int Due { getset; }        public int Completed { getset; }        public double PercentageComplete { getset; }    }

Thanks in advance,

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On October 24, 2016 11:03 AM UTC

Hi Jason, 

We suspect that you would like to bind Complex columns to the Grid. To bind the complex columns, you have to mention the field name with the corresponding field name followed by the Table name which has been concatenated by dot (.). In you case, the Complex column is like an array, so you have to concatenate the table along with an index value of the row. Refer to the following code example. 

         .Columns(col => 
            . ..  
                //Complex columns 

We have also prepared a sample that can be downloaded from the following location. 

Seeni Sakthi Kumar S. 


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

or the page will be automatically redirected to 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