Search code examples
jquerykendo-uikendo-gridkendo-template

how to show/hide and check/uncheck checkboxes dynamically inside kendo grid


I am using checkboxes inside kendo grid. I need to show and hide checkboxes dynamically using one flag , also I need to check/uncheck checkboxes dynamically using another flag.

Hence I used a template like this

template:

<input #= EQUS ? '' : style='visibility:hidden' #  type='checkbox' class='checkbox' #= IsEquityUS ? checked='checked' : '' #/>

where EQUS flag is used to show/hide checkboxes IsEquityUS flag is used to check/uncheck checkboxes

The problem is though if EQUS is false, checkbox is not hiding. So can anyone tell me the solution how to accomplish this functionality, and why the above code is not working.

Thanks in advance


Solution

  • If both isEquityUS and EQUS are part of the model of kendogrid, then instead of using inline template, you can define the template in your html.

    <script id="template" type="text/kendo-template">
       #if(EQUS != '') { #   
       <input type="checkbox" #= data.IsEquityUS ? checked="checked" : "" # />
       # } #
    </script>
    

    In the grid column, provide this template as shown below:

     columns: [
        { field: "EQUS", Title: "EQUS", width: 150 },
        {
            template: $("#template").html(),
    
        }
    ]
    check the fiddle http://jsfiddle.net/Hfk3Q/17/