Variabile Formatting in Column Template

Hello,

Is there a way to apply a format to a variable in a column template (using the new syntax?)

I tried to check the documentation for the template engine but I was not able to use any customHelper function, also looks like too tricky for a simple task like formatting a variable.

Also found this under MVC EJ2 but looks like something for MVC EJ1.

Thank you for your help,
Daniele

1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team March 21, 2018 07:03 AM UTC

Hi Daniele, 

Thanks for using Syncfusion support. 

We have achieved your requirement “Applying a Date format for template column in Grid”using Custom Helper function. Please refer to the following code example, Help documentation, 
Code example
 <Grid> 
 @Html.EJS().Grid("CommandColumn").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
       { 
 
           .   .  . 
           col.Field("OrderDate").HeaderText("Template Column").Width("150").Template("${getDateFormat(data.OrderDate)}").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
.   .  . 
 
       }).AllowPaging().PageSettings(page => page.PageCount(5)).Render() 
 
[helper function] 
<script> 
    function getDateFormat(OrderDate) { 
        var intl = new ej.base.Internationalization(); 
        var formattedDate = intl.formatDate(OrderDate, { format: 'dd/MM/yyyy' });//format the Date value 
        return formattedDate; //return the formatted date 
    } 
     
</script> 
 



We have also prepared a sample for your reference which can be download from following link, 


Please let us know if you have any further assistance on this. 

Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon