Complex Binding in column template

Hello,
In my class I have a List of object, like:

public class Person {
  public string Name { get; set }
  public List<Salary> monthSalary { get; set; }
}

And

public class Salary {
  public int Month { get; set; }
  public decimal Salary { get; set; }
}

In my controller, I populate the Person object so that it always has 12 items in the monthSalay List, one for each month.
I'm binding this to my table by doing

for(int i = 1; i <= 12; i++)
{
   col.HeaderText(i).Field("monthSalary." + i - 1 + ".Salary").Add();
}

Is this the only solution to archieve this?

Anyways, it works, but I'd like to add a template for the column like:
col.HeaderText(i).Field("monthSalary." + i - 1 + ".Salary").Template("<span class='niceClassForSalary'>${monthSalary." + i + ".Salary}</span>").Add();

If I do this, the grid shows nothing. Is there a way to access complex object in template?

Thank you

3 Replies

DA Daniele April 20, 2018 03:13 PM UTC

Ok I found I can access the complex object by doing: 
.Template("<span class='niceClassForSalary'>${monthSalary[0].Salary}</span>").Add();

but not by doing 
.Template("<span class='niceClassForSalary'>${monthSalary[" + i + "].Salary}</span>").Add();


DA Daniele April 20, 2018 03:49 PM UTC

Ok it works. I was going out of bound with the index.


RS Renjith Singh Rajendran Syncfusion Team April 23, 2018 04:12 AM UTC

Hi Daniele, 

Thanks for the update. 

We are happy to hear that you have achieved your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon