Correct way to do if statement in a client template?

5 posts, 0 answers
  1. Scott
    Scott avatar
    2 posts
    Member since:
    Mar 2011

    Posted 04 Feb 2013 Link to this post

    I'm trying to put a conditional in a client template and can't figure out where in the docs this is addressed. Could you point me to the correct area? Here's the code that's not working. The conditional is "CanBeOverturned":

    columns.Template(@<text></text>).ClientTemplate("<div>Reviewed Date : \\#=SubmissionDateString\\# | \\#=CorrectiveActionName\\# \\# if (CanBeOverturned == true) { <a href='javascript:var t=0;' onclick='javascript:return openOverturn(\"\\#=FeedbackFormId\\#\")' style='float:right;' class='openFeedbackForm')>+ Overturn</a> }</div>");

    Thanks in advance for any help you can provide!
  2. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 05 Feb 2013 Link to this post

    Hello Scott,

    There is an if example at the very bottom of this documentation article. Please let us know if you still experience troubles with your implementation.

    Regards,
    Petyo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Joe
    Joe avatar
    9 posts
    Member since:
    Mar 2013

    Posted 13 Aug 2013 Link to this post

    Hi Petyo,
    I'm struggling with the syntax of this conditional statement. I've studied the online documentation but no success.
    .ClientFooterTemplate("<div>Avg: # if(data.TotalSalesAmt.sum == 0) {#= kendo.toString(0,'P2'); #}# else {#= kendo.toString(data.TotalMarginAmt.sum / data.TotalSalesAmt.sum,'P2'); #}# </div>")
  5. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 15 Aug 2013 Link to this post

    Hello,

    As far as I see, there are some mismatched # symbols in your template. Try breaking the template to multiline string in order to debug it. 

    Regards,
    Petyo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Joe
    Joe avatar
    9 posts
    Member since:
    Mar 2013

    Posted 19 Aug 2013 Link to this post

    Breaking the statement up into separate lines was a good suggestion. This worked:
    .ClientFooterTemplate("# if(data.TotalSalesAmt.sum == 0) " +
                                               "{# <div>Avg: #= kendo.toString(0,'P2') # </div>#} " +
                                               "else {# <div>Avg: #= kendo.toString(data.TotalMarginAmt.sum / data.TotalSalesAmt.sum,'P2') # </div> #}#"
    )
Back to Top
Kendo UI is VS 2017 Ready