This is a migrated thread and some comments may be shown as answers.

[Solved] How to Hide telerik:GridTemplateColumn on check box check/uncheck event

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajeev
Top achievements
Rank 1
Rajeev asked on 16 Jul 2012, 12:44 PM

I have a Telerik MVC3 Grid with Ajax binding.
Gid have one Template column which shows the image.

I have a CheckBox control on Grid toolbar. I want to show/hide Image template column on
check box check and unchek event.

How to do this. Please help. This is urgent.

RK

3 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 18 Jul 2012, 05:38 AM
You can use javascript for doing that. I recently did a similar implementation, though not on a template column. I used it on the onDataBindning event.

$('#CheckboxID').click(function () {
 
    var grid = $("GridName").data("tGrid");
    if ($(this).is(':checked')) {
        // the checkbox was checked
        grid.showColumn("ColumnName");
 
    } else {
        // the checkbox was unchecked
        grid.hideColumn("ColumnName");
    }
});

You should be able to change the "ColumnName" to the specific index on your Column template.
0
Rajeev
Top achievements
Rank 1
answered on 20 Jul 2012, 06:18 PM
Hi Alex,
Thanks for your reply. I got this on check/uncheck event
error Microsoft JScript runtime error: Object doesn't support property or method 'showColumn'

RK
0
Alex
Top achievements
Rank 1
answered on 23 Jul 2012, 08:00 AM
I think I made a typo, the grid-variable should be outside of the click-function. I tried it and this works for me. Like this:

function onDataBinding(e) {
 
    var grid = $("#GridName").data("tGrid");
 
    $('#CheckboxID').click(function () {
 
        if ($(this).is(':checked')) {
            // the checkbox was checked
            grid.showColumn(0); //show column that has index 0.
 
        } else {
            // the checkbox was unchecked
            grid.hideColumn(0);
        }
    });
}
Tags
Grid
Asked by
Rajeev
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Rajeev
Top achievements
Rank 1
Share this question
or