# Templates

The Telerik UI PivotGridV2 HtmlHelper for ASP.NET MVC provides built-in templates, which allow you to customize the way the data is displayed in the table.

The templates use the [Kendo UI Templates syntax](https://docs.telerik.com/kendo-ui/framework/templates/overview).

The available types of PivotGridV2 templates are:

* [Data cell template](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/pivotgridv2/templates#data-cell-template)
* [Column header template](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/pivotgridv2/templates#column-header-template)
* [Row header template](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/pivotgridv2/templates#row-header-template)
* [KPI Status Template](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/pivotgridv2/templates#kpi-status-template)
* [KPI Trend Template](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/pivotgridv2/templates#kpi-trend-template)

For a live example, see the [PivotGridV2 Templates](https://demos.telerik.com/aspnet-mvc/pivotgridv2/templates) demo.

## Data Cell Template

The data cell template is the [template](https://docs.telerik.com/kendo-ui/api/kendo/methods/template) which renders the content of the data cell. By default, it renders the `fmtValue` formatted value of the data item.

In the data cell template, you can access the following fields:

* `columnTuple`—The tuple of the corresponding column header cell.
* `rowTuple`—The tuple of the corresponding row header cell.
* `measure`—The value of the data cell measure.
* `dataItem`—The data item itself.

```Razor HtmlHelper
    @(Html.Kendo().PivotGrid()
        .Name("pivotgrid")
        .ColumnWidth(200)
        .Height(570)
        .DataCellTemplateId("dataCellTemplate")
        // Other configuration.
    )
```

```JS Template
    <script id="dataCellTemplate" type="text/x-kendo-tmpl">
        # var columnMember = columnTuple ? columnTuple.members[0] : { children: [] }; #
        # var rowMember = rowTuple ? rowTuple.members[0] : { children: [] }; #
        # var value = kendo.toString(kendo.parseFloat(dataItem.value) || "N/A", "c2"); #

        # if (columnMember.children.length || rowMember.children.length) { #
            <em  style="color: red">#: value # (total)</em>
        # } else { #
            #: value #
        # } #
    </script>
```

## Column Header Template

The column header template is the [template](https://docs.telerik.com/kendo-ui/api/kendo/methods/template) which renders the content of the column header cell. By default, it renders the caption of the tuple member.

In the column header template, you can access the following fields:

* `member`—The member of the corresponding column header cell.
* `tuple`—The tuple of the corresponding column header cell.

```Razor HtmlHelper
    @(Html.Kendo().PivotGridV2()
        .Name("pivotgridv2")
        .ColumnWidth(200)
        .Height(570)
        .ColumnHeaderTemplateId("headerTemplate")
        // other configuration settings
    )
```

```JS Template
    <script id="headerTemplate" type="text/x-kendo-tmpl">
        # if (!member.children.length) { #
            <em>#: member.caption #</em>
        # } else { #
            #: member.caption #
        # } #
    </script>
```

## Row Header Template

The row header template is the [template](https://docs.telerik.com/kendo-ui/api/kendo/methods/template) which renders the content of the row header cell. By default, it renders the caption of the tuple member.

In the row header template, you can access the following fields:

* `member`—The member of the corresponding column header cell.
* `tuple`—The tuple of the corresponding column header cell.

```Razor HtmlHelper
    @(Html.Kendo().PivotGridV2()
        .Name("pivotgridv2")
        .ColumnWidth(200)
        .Height(570)
        .RowHeaderTemplateId("headerTemplate")
        // other configuration settings
    )
```

```JS Template
    <script id="headerTemplate" type="text/x-kendo-tmpl">
        # if (!member.children.length) { #
            <em>#: member.caption #</em>
        # } else { #
            #: member.caption #
        # } #
    </script>
```

## KPI Status Template

The [template](https://docs.telerik.com/kendo-ui/api/kendo/methods/template) which renders the content of the `KPI Status` value. By default renders "open", "hold" and "denied" status icons.

The fields which can be used in the template are:

* `columnTuple`—the tuple of the corresponding column header cell
* `rowTuple`—the tuple of the corresponding row header cell
* `measure`—the value of the data cell measure
* `dataItem`—the data item itself

```Razor HtmlHelper
    @(Html.Kendo().PivotGridV2()
        .Name("pivotgrid")
        .ColumnWidth(200)
        .Height(580)
        .KpiStatusTemplateId("kpiStatusTemplate")
        .DataSource(dataSource => dataSource
        .Xmla()
        .Columns(columns => {
            columns.Add("[Date].[Calendar]").Expand(true);
            columns.Add("[Product].[Category]");
        })
        .Rows(rows => rows.Add("[Geography].[City]"))
        .Measures(measures => measures.Values(v => {
            v.Add().Name("[Measures].[Internet Revenue Status]").Type("status");
        }))
        .Transport(transport => transport
            .Connection(connection => connection
                .Catalog("Adventure Works DW 2008R2")
                .Cube("Adventure Works"))
                .Read("https://demos.telerik.com/service/v2/olap/msmdpump.dll")
            )
        )
    )
```

```JS Template
    <script id="kpiStatusTemplate" type="text/x-kendo-tmpl">
        # if (!dataItem) { #
            <em>N/A</em>
        # } else if(parseInt(dataItem.value) > 0) { #
            <em>Open</em>
        # } else if(parseInt(dataItem.value) < 0) { #
            <em>Hold</em>
        # } else { #
            <strong>Denied</strong>
        # } #
    </script>
```

## KPI Trend Template

The [template](https://docs.telerik.com/kendo-ui/api/kendo/methods/template) which renders the content of the `KPI Trend` value. By default renders "increase", "decrease" and "equal" status icons.

The fields which can be used in the template are:

* `columnTuple`—the tuple of the corresponding column header cell
* `rowTuple`—the tuple of the corresponding row header cell
* `measure`—the value of the data cell measure
* `dataItem`—the data item itself

```Razor HtmlHelper
    @(Html.Kendo().PivotGridV2()
        .Name("pivotgrid")
        .ColumnWidth(200)
        .Height(580)
        .KpiTrendTemplateId("kpiTrendTemplate")
        .DataSource(dataSource => dataSource
        .Xmla()
        .Columns(columns => {
            columns.Add("[Date].[Calendar]").Expand(true);
            columns.Add("[Product].[Category]");
        })
        .Rows(rows => rows.Add("[Geography].[City]"))
        .Measures(measures => measures.Values(v => {
            v.Add().Name("[Measures].[Internet Revenue Trend]").Type("trend");
        }))
        .Transport(transport => transport
            .Connection(connection => connection
                .Catalog("Adventure Works DW 2008R2")
                .Cube("Adventure Works"))
                .Read("https://demos.telerik.com/service/v2/olap/msmdpump.dll")
            )
        )
    )
```

```JS Template
    <script id="kpiTrendTemplate" type="text/x-kendo-tmpl">
        # if (!dataItem) { #
            <em>N/A</em>
        # } else if(parseInt(dataItem.value) > 0) { #
            <em>Increase</em>
        # } else if(parseInt(dataItem.value) < 0) { #
            <em>Decrease</em>
        # } else { #
            <strong>Equal</strong>
        # } #
    </script>
```

## See Also

* [Templates in the Telerik UI PivotGridV2 HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/pivotgridv2/templates)
* [Server-side API](https://www.telerik.com/aspnet-mvc/documentation/api/pivotgridv2)
