)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to set the format for the template column in grid?

Platform: jQuery |
Control: ejGrid |
Published Date: June 7, 2018 |
Last Revised Date: February 25, 2020

This Knowledge base explains that how to set the format for the template column in Grid.

Solution:

By default, in template column the value will be rendered based on the templates that we specified in the template property.

For template manipulation i.e., to set the format for the template column we have to use templateRefresh event of ejGrid.

The following code example demonstrates how to set the format for the template column using templateRefresh event of ejGrid.

JS:

1. Render the Grid Control.

 
<div id="Grid"></div>
           
    <script type="text/javascript">
        $(function () {
            $("#Grid").ejGrid({
                // the datasource "window.gridData" is referred from jsondata.min.js
                dataSource: window.gridData,
                allowPaging: true,
                pageSettings: { pageSize: 4 },
                templateRefresh : "templateRefresh",
                columns: [
                    { headerText: "Total Values", template: '<span>{{:EmployeeID + Freight}}</span>', width: 110 },
                    { field: "OrderID", headerText: "Order ID", textAlign: ej.TextAlign.Right, width: 90 },
                    { field: "CustomerID", headerText: "Customer ID", width: 90 },
                ]
            });
        });
    </script> 
 

 

 

MVC:

 
@(Html.EJ().Grid<object>("HeaderTemplate")
     .Datasource((IEnumerable<object>)ViewBag.datasource)
     .AllowPaging()
     .PageSettings(page => { page.PageSize(4); })
     .ClientSideEvents(eve => eve.TemplateRefresh("templateRefresh"))
     .Columns(col =>
      {
        col.HeaderText("Total Values").Template("<span>{{:EmployeeID + Freight}}</span>").Width(110).Add();
        col.Field("OrderID").HeaderText("Order ID").TextAlign(TextAlign.Right).Width(90).Add();
        col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
     })
)

 

ASP.NET:

 
<ej:Grid ID="EmployeesGrid" runat="server" AllowPaging="True">
            <PageSettings PageSize="4"></PageSettings>
            <ClientSideEvents TemplateRefresh="templateRefresh" />
            <Columns>
                <ej:Column HeaderText="Total Values" Template="<span>{{:EmployeeID + Freight}}</span>" TextAlign="Center" Width="110" />
                <ej:Column Field="OrderID" HeaderText="Order ID" TextAlign="Right" Width="90" />
                <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="80" />
            </Columns>
</ej:Grid>
 

 

 ASP.NET CORE:

 
<ej-grid id="Grid" datasource="(IEnumerable<object>)ViewBag.dataSource" allow-paging="true" template-refresh="templateRefresh">
    <e-page-settings page-size="4"></e-page-settings>
    <e-columns>
        <e-column header-text="Total Values" width="110" template='<span>{{:EmployeeID}} + {{:Freight}}</span>'></e-column>
        <e-column field="OrderID" header-text="Order ID" text-align="Right" width="90"></e-column>
        <e-column field="CustomerID" header-text="Customer ID" width="80"></e-column>
    </e-columns>
</ej-grid>
 

 

 

 

JS:

2. In templateRefresh event we apply for the template column using ej.format method.

 
function templateRefresh(args) {
    var value = parseFloat($(args.cell).text()); 
    $(args.cell).text(ej.format(value, "C2"))
 }

Result:

Formatted template column Grid

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon