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. Image for the cookie policy date
close icon

Format date for link column

I have a link column in grid like this:
col.Field("DatumOd").HeaderText("Datum/vrijeme od").Width(110)
     .Format("<a id='editDN' rel='nofollow' href='#' onclick='editDnevnice({DnevniceID});return false;'>{DatumOd}</a>").Add();
which I'm using for oppening modal window to edit and it works just fine. 

How can I format link text {DatumOd} for example like {0:dd.MM.yyyy. HH:mm}?

Thanks!
B.

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team May 31, 2017 10:21 AM UTC

Hi Bernard,  
 
Thanks for contacting Syncfusion Support.  
 
We could see you would like to bind the hyperlink to Grid Columns. By default, Grid provides an option to place any HTML elements in the Grid cells using the Column Template concept. Refer to the following following Help Documents and Sample demo. 
 
 
Using the jsRender concept template columns will render the given data and therefore, we can use the helper functions to customize the rendering actions. In the following code example, helper function has been used in which the ej.format has been used to format the date in required format. 
 
<script type="text/x-jsrender" id="columnTemplate"> 
    <a id='editDN' rel='nofollow' href='#' dataval="{{:~formatDate(#data['HireDate'])}}" onclick='return editDnevnice(this);'>{HireDate}</a> 
</script> 
 
@{Html.EJ().Grid<object>("Grid") 
        .Datasource((IEnumerable<object>)ViewBag.data) 
        .Columns(col => 
        { 
            col.HeaderText("Employee Image").Template("#columnTemplate").Add(); 
               . . . . .  
                   . .. .  
        }) 
        .Render(); 
} 
<script type="text/javascript"> 
    var helpers = { 
        formatDate: function (Date) { 
            return ej.format(Date, "dd.MM.yyyy HH:mm"); 
        } 
    };//helpers 
    $.views.helpers(helpers); 
    function editDnevnice(args) { 
        var val = $(args).attr("dataVal"); 
    } 
</script> 
 
 
 
Refer to the output for the code example. 
 
 
 
 
Regards,  
Seeni Sakthi Kumar S. 



BJ Bernard Jurlina May 31, 2017 09:08 PM UTC

Thanks Kumar,
excellent! The ColumnTemplate with formatDate helper is what I was looking for.

Regards,
Bernard.


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team June 1, 2017 04:03 AM UTC

Hi Bernard,  
 
Thanks for the update. We are happy to hear that your requirement has been achieved. If you required further assistance on this, please get back to us.  
 
Regards,  
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon