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

[Solved] How to check all checkboxes in a template column, client side?

1 Answer 282 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 14 May 2008, 08:34 PM
I don't have a good enough understanding of the new client side API to figure out how to migrate my Javascript for the ASP.Net grid to the new AJAXK version.

I have a template column:

<

telerik:GridTemplateColumn ShowSortIcon="False" UniqueName="Selector">
<ItemTemplate>
<asp:CheckBox ID="INPUT" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="SelectAllCheckBox" type="checkbox" onclick="CheckBoxChanged()" />
</HeaderTemplate>
</telerik:GridTemplateColumn>

and previously this Javascript would select all the checkboxes:

function

CheckAll()
{
   var checkboxes = grid.MasterTableView.Control.getElementsByTagName("INPUT");
   for (var index = 0; index < checkboxes.length; index++)
   {
      if( ! checkboxes[index].checked )
      {
         checkboxes[index].checked =
true;
      }
   }
}

(the CheckBoxChanged() function merely calls CheckAll() or UnCheckAll()) I can't use a select column, because selecting a row fires a different event. Like I said, I don't know enough yet about the client side API, and I'm pressed for time - how would I convert the above Javascript? Thanks.

Bill

1 Answer, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 14 May 2008, 09:05 PM
Figured it out; it may not be elegant but it seems to work...

function

CheckAll()
{
   var masterTable = grid.get_masterTableView();
   var checkboxes = masterTable.get_dataItems();
   for (var index = 0; index < checkboxes.length; index++)
   {
      var checkBoxCell = masterTable.getCellByColumnUniqueName(checkboxes[index], "Selector");
      if (checkBoxCell == null)
         continue;
      checkBoxCell.childNodes[0].checked =
true;
   }
}

Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Share this question
or