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

RadGrid - Checkbox column - databound - get + set value via javascript

1 Answer 322 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 Dec 2020, 05:11 PM

Hi,

 

I have a databound radgrid and I need to get and set the value of a checkbox column client side.

I'm using the following for the other columns, which I have adapted from code found on this site.

 

    var myMasterTable = Grid.get_masterTableView();
    var myCell = myMasterTable.getCellByColumnUniqueName(myMasterTable.get_dataItems()[myRowIndex - 1], ColumnName);
    var myCellValue = myCell.innerHTML;
    if (myCellValue == " ") { myCellValue = ""; }
    return myCellValue;

 

But unlike the other columns it returnsthe below html and not the actual value?

"<span class="aspNetDisabled"><input id="grid_Properties_ctl00_ctl04_ctl50" type="checkbox" name="grid_Properties$ctl00$ctl04$ctl50" checked="checked" disabled="disabled"></span>"

 

How do I get the checked state and also set the checked state via javascript? Is their abuilt in method for this?

 

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 07 Dec 2020, 03:00 PM

Hi Chris,

The value of the GridCheckbox column is not set as text of the column like in the data bound columns but is used as a value for the underlying checkbox.

You can access its value through the checked property of the input element:

                 var myMasterTable = Grid.get_masterTableView();
                 var myCell = myMasterTable.getCellByColumnUniqueName(myMasterTable.get_dataItems()[myRowIndex - 1], ColumnName);
                 var myInput = $telerik.$(myCell).find("input")[0];
                 var myCellValue = myInput.checked;
                 //test myInput.checked = false;
                 if (myCellValue == "&nbsp;") { myCellValue = ""; }
                 return myCellValue;

 

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or