Premmerce Documentation > Table or Grid > Custom Column Template
About Premmerce
Installation
Table or Grid
CSS and JS
General
Go to Helpers
folder > TableConfig.cs
Go to the specific TableConfig
class that you want to modify.
Add a ColumnHtmlTemplate
property to the custom column definition. For example:
public static List<ColumnProperty> TableColumns = new List<ColumnProperty>() {
new ColumnProperty { HeaderKey =nameof(TicketViewModel.Code),ColumnHtmlTemplate = "_MyCustomTemplate"}
};
Add a partial view named _MyCustomTemplate.cshtml
in one of the following locations:
/Views/Shared
/Views/TheController
The examples below demonstrates how it works.
public static class ManageOrderTableConfig
{
public static List<ColumnProperty> TableColumns = new List<ColumnProperty>() {
new ColumnProperty { HeaderKey =nameof(OrderViewModel.Id), ColumnHtmlTemplate = "_Checkbox",ColumnMinWidth="50", IsCheckbox = true,Sortable=false }
};
}
@model ColumnHtmlTemplateViewModel
@{
object id = Model.ColumnsInCurrentRow.Where(a => a.HeaderKey == nameof(OrderViewModel.Id)).Select(a => a.Value).FirstOrDefault() ?? "";
object statusCode = Model.ColumnsInCurrentRow.Where(a => a.HeaderKey == nameof(OrderViewModel.StatusCode)).Select(a => a.Value).FirstOrDefault() ?? "";
}
<!-- Display checkbox only when order is not "Refunded" -->
<!-- Status cannot be changed once an order is refunded -->
@if (Convert.ToString(statusCode) != ProjectEnum.OrderStatus.Refunded.ToString())
{
<div class="form-check">
<input class="form-check-input" type="checkbox" value="@id">
</div>
}