|
<SfGrid DataSource="@Employees" Height="315">
<GridColumns>
<GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="EmployeeID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field="Name.FirstName" HeaderText="First Name" Width="150"></GridColumn>
<GridColumn Field="Name.LastName" HeaderText="Last Name" Width="130"></GridColumn>
<GridColumn Field=@nameof(EmployeeData.Title) HeaderText="Title" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<EmployeeData> Employees { get; set; }
. . .
public class EmployeeData
{
public int? EmployeeID { get; set; }
public EmployeeName Name { get; set; }
public string Title { get; set; }
}
public class EmployeeName
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
} |
Hi Paul,
Greetings from Syncfusion.
We have validated your query and we suspect that you are facing problem while binding complex data. You can achieve complex data binding in the datagrid by using the dot(.) operator in the column.field. In the below examples Name.FirstName and Name.LastName are complex data.
<SfGrid DataSource="@Employees" Height="315"><GridColumns><GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="EmployeeID" TextAlign="TextAlign.Right" Width="120"></GridColumn><GridColumn Field="Name.FirstName" HeaderText="First Name" Width="150"></GridColumn><GridColumn Field="Name.LastName" HeaderText="Last Name" Width="130"></GridColumn><GridColumn Field=@nameof(EmployeeData.Title) HeaderText="Title" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn></GridColumns></SfGrid>@code{public List<EmployeeData> Employees { get; set; }. . .public class EmployeeData{public int? EmployeeID { get; set; }public EmployeeName Name { get; set; }public string Title { get; set; }}public class EmployeeName{public string FirstName { get; set; }public string LastName { get; set; }}}
Reference:
If you are still facing the problem or if we misunderstood your problem, then could you please share the below details. It will be helpful to validate and provide a better solution.
- Full Grid code snippets.
- Share your model class details.
- Share a simple reproduceable sample if possible.
Regards,Rahul
|
[ServiceList.razor]
<SfGrid DataSource="@services"
AllowPaging="true"
. . .>
<GridPageSettings PageSize="20"></GridPageSettings>
<GridEvents RowDeselected="RowDeSelectedHandler" RowSelected="RowSelectedHandler" TValue="ServiceForListDto"></GridEvents>
<GridColumns>
HeaderText="Service Code #" TextAlign="@TextAlign.Right"
Width="70">
</GridColumn>
HeaderText="Service Name" TextAlign="@TextAlign.Left"
Width="80">
</GridColumn>
<GridColumn Field="Category.Name"
HeaderText="Category" TextAlign="@TextAlign.Left"
</GridColumn>
. . .
</GridColumns>
</SfGrid> |
|
<GridColumn Field="Category.Name"
HeaderText="Category" TextAlign="@TextAlign.Left"
</GridColumn> |