User
User

Reputation: 1662

how to add condition in kendo grid view

I need to show/hide remove(delete( icon)based on condition.for ex var a=2,var b=2;if(a=b) need to show the icon.But a!=b means hide the delete icon.How to do this?

{
  command: {
              template: kendo.template($("#remove").html())                
            }, title: " ", width: "40px"
 }

<script id="remove" type="text/x-kendo-tmpl">
    <a href="" onclick="remove(this); return false;">
        <img src="@Url.Content("~/Images/delete_icon.gif")" alt="Remove item" />
    </a>
</script>

Upvotes: 2

Views: 655

Answers (1)

Iman Mahmoudinasab
Iman Mahmoudinasab

Reputation: 7015

You can use javascript in your templates:

<script id="remove" type="text/x-kendo-tmpl">
    # var a=2; var b=2;#
    # if(a==b){ #
    <a href="" onclick="remove(this); return false;">
        <img src="@Url.Content("~/Images/delete_icon.gif")" alt="Remove item" />
    </a>
    # } #
</script>

Check Kendo UI Templates Overview for more detailed examples and different Template Syntax of kendo:

  1. Render literal values: #= #
  2. Render HTML-encoded values: #: #
  3. Execute arbitrary JavaScript code: # if(...){# ... #}#

Upvotes: 2

Related Questions