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

change checkboxes values in cascade

2 Answers 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 19 May 2009, 09:32 AM
Hello,

I'm using a hierarchical radgrid control which has three levels (a master and two detail tables). Each row has a template column that contains a checkbox. What I want to do is to check all checkboxes in the hierarchy when checkbox in the inner row is checked, and I would like to achieve this in client code. 

The only thing I've been able to get is catching the click event on the checkbox and finding the row where the checkbos control is:

     function CkeckBox_Click(e) {      
      if (e.target) {
        gridRow = e.target.parentNode.parentNode;
      }
      else {
        gridRow = e.srcElement.parentNode.parentNode;
      }

Could you please help me?
Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Luis
Top achievements
Rank 1
answered on 20 May 2009, 11:49 AM
Hello,

this is the solution I have found. I post it just in case anyone else face the same problem.

  <script type="text/javascript">
    function ToggleSelection(e) {
      var checkbox;
      var gridRow;
      var grid = $find('<%=RadGrid1.ClientID %>');
      var masterTable = grid.get_masterTableView();
      
      checkbox = e.srcElement;
      gridRow = checkbox.parentNode.parentNode;

      IterateGrid(gridRow, masterTable.get_dataItems());

// Some other code     
    }

    function IterateGrid(gridRow, gridItems) {
      var found = false;
      
      for (var n = 0; n < gridItems.length; n++) {
        if (gridItems[n].get_element().id == gridRow.id) {
          found  = true;
        }
        else {          
          for (var i = 0; i < gridItems[n].get_nestedViews().length; i++) {
            found  = RecorreGrid(gridRow, gridItems[n].get_nestedViews()[i].get_dataItems());
            if (found) {
              gridItems[n].get_element().cells[4].childNodes[0].checked = 'checked';
              break;
            }
          }
        }

        if (found)
          break;
      }
      
      return found ;
    }

</script>


My grid has two detail tables and a template column (4-index) that contains an input control of type checkbox.
0
Yavor
Telerik team
answered on 22 May 2009, 06:26 AM
Hi Luis,

Indeed, this is one possible approach to handle this task. Thank you for sharing it with the community.
Your Telerik points have been updated accordingly.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Luis
Top achievements
Rank 1
Answers by
Luis
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or