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

My grid column template does not work.

Why my grid column template is not working

@(Html.EJ().Grid<ApplicationCore.Entities.Distributor>("TGrid")
            .Datasource(dataSource =>
            {
                dataSource.Json(Model);
                dataSource.Adaptor(AdaptorType.RemoteSaveAdaptor);
                dataSource.CrudURL(Url.Action("Crud"));
                dataSource.SerializerMode(SerializerMode.NewtonSoft);
                dataSource.SerializerSettings(new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            })
            .Columns(col =>
            {
                col.Field(c => c.Id).IsPrimaryKey(true).IsIdentity(true).Add();
                col.Field(c => c.DistributorName).Add();
                col.Field(c => c.FriendlyUrl).Add();
                col.Field(c => c.WebsiteUrl).Add();
                col.Field(c => c.ImageFilename).Template("#template").Add();
                col.Field(c => c.ListImageFilename).Add();
            })


<script id="template" type="text/x-template">
    <a rel='nofollow' href="@Url.Content("~/${ImageFilename}")" target="_blank">${ImageFilename}</a>
</script>

It will render 

${ImageFilename}

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 7, 2020 12:48 PM UTC

Hi Daniel, 

Thanks for contacting Syncfusion Support. 

We have checked your query and we have prepared sample with ColumnTemplate but we are unable to reproduce the problem at our end. Refer to the code example:- 

     @(Html.EJ().Grid<object>("HierarchyGrid") 
                    .Datasource((IEnumerable<object>)ViewBag.datasource 
                     .Columns(col => { 
                               col.Field("EmployeeID").HeaderText("Image").Template("#template").TextAlign(TextAlign.Right).Width(75).Add(); 
                                col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
                            }) 
                ) 
 
<script id="template" type="text/x-template"> 
    <a rel='nofollow' rel='nofollow' href="@Url.Content("~/${ImageFilename}")" target="_blank">{{:EmployeeID}}</a> 
</script> 

Note:- If you want to render the FieldName values for template you need to define the FieldName inside double braces followed with Colon {{:ImageFileName }} but in your code example it was like ${ImageFileName}. So it has been rendered the same. 
 
Refer to the sample Link:- 
 
Demo and Documention Links:- 

Still faced issue, please share us the screenshot or replicate the issue in the above sample and revert us. 

Regards, 
Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon