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

How to iterate a RadGrid using javascript to find whether checkboxes are checked for each row

5 Answers 600 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jnh999
Top achievements
Rank 1
jnh999 asked on 27 Mar 2013, 06:26 PM
Hi, Telerik,
I have a RadGrid with a checkbox in each row.  I need to use JavaScript to iterate each row and check and see whether each row are checked. The checkbox is defined in <telerik:GridTemplateColumn> in MasterTableView.  How do I do that? 

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Mar 2013, 04:15 AM
Hi,

Try the following javascript.
JS:
function onclick() {
   var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
   var row = masterTable.get_dataItems();
   for (var i = 0; i < row.length; i++)
   {
       var chk=masterTable.get_dataItems()[i].findElement("CheckBox1");
   }
}

Thanks,
Shinu
0
jnh999
Top achievements
Rank 1
answered on 28 Mar 2013, 05:02 PM
Thank you.  It worked.
Another follow up question.  I need to get other values in the same row.  How do I get that.  the rendered html is as follows:

<td>
<span title="CV-2">
<input id="ctl00_ctl00_ctl00_ctl00_BodyPlaceHolder_ContentPlaceHolder_ContentPlaceHolder_mainContentPlaceHolder_ucArchitectureFile_ucArchitectureFileGrid2_rgArchitectureFiles_ctl00_ctl05_IncludeFileCheckBox" type="checkbox" checked="checked" name="ctl00$ctl00$ctl00$ctl00$BodyPlaceHolder$ContentPlaceHolder$ContentPlaceHolder$mainContentPlaceHolder$ucArchitectureFile$ucArchitectureFileGrid2$rgArchitectureFiles$ctl00$ctl05$IncludeFileCheckBox">
</span>
<input id="ctl00_ctl00_ctl00_ctl00_BodyPlaceHolder_ContentPlaceHolder_ContentPlaceHolder_mainContentPlaceHolder_ucArchitectureFile_ucArchitectureFileGrid2_rgArchitectureFiles_ctl00_ctl05_hiddenArchitectureFileId" type="hidden" value="3115" name="ctl00$ctl00$ctl00$ctl00$BodyPlaceHolder$ContentPlaceHolder$ContentPlaceHolder$mainContentPlaceHolder$ucArchitectureFile$ucArchitectureFileGrid2$rgArchitectureFiles$ctl00$ctl05$hiddenArchitectureFileId">
</td>

What follow up api should I call to get the span title "CV_2" and also the value="3115" in the input.

I am new to using javascript.  thank you for your help.

0
Shinu
Top achievements
Rank 2
answered on 01 Apr 2013, 12:38 PM
Hi,

Try the following javascript.
JS:
function onclick() {
   var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
   var row = masterTable.get_dataItems();
   for (var i = 0; i < row.length; i++)
   {
       var input=masterTable.get_dataItems()[i].findElement("input1");
   }
}

Thanks,
Shinu
0
kunigiri
Top achievements
Rank 1
answered on 16 Dec 2015, 10:46 AM

Hi 

 i am using this code but i am not getting the Mastertable view data. it is showing error.undefined.my requirement is i am having telerik gird with check box and bound column , on submit click for that page i need to check whether the check box is clicked or not , if no check box does not checked then need alert message. please help me in this as soon possible.

Thanks 

indraja

0
Eyup
Telerik team
answered on 21 Dec 2015, 09:22 AM
Hi Кunigiri,

You can traverse the grid items and once you have a reference to the the grid item within the for loop, you can use findElement or findControl methods to get the checkBox or simply use the get_selected() method:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/traversing-detail-tables#looping-through-the-detail-tablesitems-in-telerik-radgrid-on-the-client

I am also sending a sample RadGrid web site to demonstrate a practical implementation with findControl() and findElement() methods. Please examine the attached application and let me know if it helps you.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
jnh999
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
jnh999
Top achievements
Rank 1
kunigiri
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or