Conditional Statement Client Template

3 Answers 5261 Views
Grid
Kieran
Top achievements
Rank 1
Kieran asked on 07 Aug 2015, 08:23 AM

I've got a grid with a client template and need to escape the conditional statement active, but I can't work out how to do it. 

I've tried

col.Bound(c => c.Active).ClientTemplate("\\# if (Active == true) {#<button class='btn btn-success'>\\#: Active\\#</button>#} \\#");
 
col.Bound(c => c.Active).ClientTemplate("# if (\\Active\\ == true) {#<button class='btn btn-success'>\\#: Active\\#</button>#} #");​​
 
col.Bound(c => c.Active).ClientTemplate("# if (\\#:Active\\# == true) {#<button class='btn btn-success'>\\#: Active\\#</button>#} #");

Template code:

 

 

<script type="text/x-kendo-tmpl" id="projectsGridClientTemplate">
    @(
 Html.Kendo().Grid<TeamProjectViewModel>().Name("projectGridDetail_#=Id#")
        .Columns(col =>
        {
            col.ForeignKey(c => c.TeamId, (SelectList)ViewBag.Teams);
            col.ForeignKey(c => c.ProjectId, (SelectList)ViewBag.Projects);
            col.Bound(c => c.Active).ClientTemplate("# if (Active == true) {#<button class='btn btn-success'>\\#: Active\\#</button>#}#");
             
        })
        .DataSource(ds => { ds.Ajax().Read(r => r.Action("GetTeamProjects", "ResourcePlannerApi", new { @projectId = "#=Id#" })); })
        .ToClientTemplate()
    )
</script>

3 Answers, 1 is accepted

Sort by
0
eo
Top achievements
Rank 1
answered on 07 Aug 2015, 03:46 PM

Hello Kieran,
 When using the ClientTemplate with conditionals it should follow this structure: # if(...){# ... #}#


Your code should look like this: 

col.Bound(c => c.Active).ClientTemplate("#if(Active){#<button class='btn btn-success'>Active</button>#}#");

Hope this helps.
Jokull
Top achievements
Rank 1
commented on 29 Aug 2018, 01:46 AM

Did that work? Doesn't work for me. If this didn't work, did you find out how to make it work?
Chinmay
Top achievements
Rank 1
commented on 06 May 2021, 03:34 PM

Thanks eo It worked for me !!!
0
Eyup
Telerik team
answered on 29 Aug 2018, 10:50 AM
Hi Kieran,

You can find a similar sample demonstrated in the following section:
https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-display-checkboxes-in-ajax-bound-grids

I hope this will prove helpful in achieving the mentioned requirement.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
BR Developer
Top achievements
Rank 1
commented on 26 Jul 2019, 04:07 PM

 columns.Bound(c => c.PersonID).Hidden(false); // Shows the PersonID here
 columns.Bound(c => c.PersonID).Title("").Filterable(false).ClientTemplate("# if (PersonID == 0) { #<a href='/Test/Supervisor/Edit?Person=\\#:PersonRequestID\\#'>View</a># }else {#<a href='/Test/Supervisor/ViewPerson?PersonID=\\#:PersonID\\#'>View</a>#} #");

When I check for PersonID == 0, here the PersonID is always 0 but it shows the PersonID in the link (\\#:PersonID\\). What should I do to get the PersonID inside the if condition show up? 

 

0
Eyup
Telerik team
answered on 29 Jul 2019, 07:52 AM
Hello,

Try using this syntax: 
#= ProductID #

Or the approach from this section:
https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-use-action-links

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Kieran
Top achievements
Rank 1
Answers by
eo
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or