ComponentOne ASP.NET MVC Controls
Custom Cell Template
Working with Controls > FlexGrid > Work with FlexGrid > Custom Cell Template

FlexGrid has an itemFormatter property that gives you complete control over the contents of the cells. MVC Edition provides CellTemplate to let users customize the cell content in FlexGrid control. To define a cell template for a column, add the HTML to display in each cell to the column definition.

The following image shows how the FlexGrid appears on setting FlexChart as a cell template to represent Trends, and Stars as another template for representing Rank. The example uses Sale.cs model added in the QuickStart section.

The following code examples demonstrate how to set the custom cell templates in a column of the FlexGrid:

In Code


Copy Code
public ActionResult CustomCells()
    return View(Sales.GetData(15));


Copy Code
@using MVCFlexGrid.Models
@model IEnumerable<Sale>

<script id="template1" type="text/html">
        .Width(100).Height(20).CssStyle("padding", "0")
        .TemplateBind("ItemsSource", "Trends")
        .Series(s => s.Add().Binding("Data"))

    .star-highlighted {
        color: orange;

    .star-dimmed {
        color: lightgray;

<script type="text/javascript">
    function rankFormatter(panel, r, c, cell) {
        if (panel.columns[c].binding === "Rank") {
   = "";
            if (panel.cellType === wijmo.grid.CellType.Cell) {
                cell.innerHTML = buildRank(panel.getCellData(r, c));

    function buildRank(rank) {
        var markup = "", j, starType;
        for (j = 0; j < 5; j++) {
            starType = j < rank ? "star star-highlighted" : "star star-dimmed";
            markup += "<span class='" + starType + "'>\u2605</span>";
        return markup;

    .Columns(columns =>
        columns.Add(column => column.Binding("ID"));
        columns.Add(column => column.Binding("Country"));
        columns.Add(column => column.Binding("Product"));
        columns.Add(column => column.Header("Trends").CellTemplate(b => b.Template("template1")));
        columns.Add(column => column.Binding("Rank"));
See Also