Table functions > Content in a column
Crud Elite
Action Column
Table functions
Common issues
Other
How it works
Please follow the steps below.
Go to /Views/Home/_Table.cshtml
.
Find the code below. It’s the original code that displays the columns based on the settings in ClientTableConfig
.
@foreach (var column in CrudElite.Helpers.ClientTableConfig.TableColumns)
{
<td class="d-block d-lg-table-cell py-2 py-lg-3">@item.GetType().GetProperty(column.Title)?.GetValue(item, null)</td>
}
Let’s say we want to dynamically display the “Name” with the following condition.
You can do the following to achieve this.
@foreach (var column in CrudElite.Helpers.ClientTableConfig.TableColumns)
{
**if (column.Title == nameof(ClientViewModel.Name))
{
<td class="d-block d-lg-table-cell py-2 py-lg-3 @(item.Name.Length > 5 ? "text-warning" : "text-danger")">@item.Name</td>
}**
else
{
<td class="d-block d-lg-table-cell py-2 py-lg-3">@item.GetType().GetProperty(column.Title)?.GetValue(item, null)</td>
}
}