Conditional Statement Client Template

6 posts, 0 answers
  1. Kieran
    Kieran avatar
    5 posts
    Member since:
    Aug 2014

    Posted 07 Aug 2015 Link to this post

    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>

  2. eo
    eo avatar
    27 posts
    Member since:
    Jul 2015

    Posted 07 Aug 2015 in reply to Kieran Link to this post

    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.
  3. Jokull
    Jokull avatar
    15 posts
    Member since:
    Oct 2016

    Posted 28 Aug 2018 Link to this post

    Did that work? Doesn't work for me. If this didn't work, did you find out how to make it work?
  4. Eyup
    Admin
    Eyup avatar
    4046 posts

    Posted 29 Aug 2018 Link to this post

    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.
  5. Dev
    Dev avatar
    4 posts
    Member since:
    Jan 2015

    Posted 26 Jul 2019 Link to this post

     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? 

     

  6. Eyup
    Admin
    Eyup avatar
    4046 posts

    Posted 29 Jul 2019 Link to this post

    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.
Back to Top