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

How to use index when RadGrid has GridTableViews?

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 08 Feb 2011, 03:47 PM

Hello, I have following RadGrid containing nested GridTableViews. Every row has CheckBox and I would like to select and deselect them in ClientSide. I have following Javascript code.

function RowSelected(sender, eventArgs) {
  
    var dataItem = sender.get_masterTableView().get_dataItems()[eventArgs._itemIndexHierarchical];
    var str = eventArgs._itemIndexHierarchical; 
  
    if (typeof (dataItem) == "undefined") {
        dataItem = sender.get_detailTables()[0].get_selectedItems()[str];
    }
  
    if (typeof (dataItem) == "undefined") {
        dataItem = sender.get_detailTables()[1].get_selectedItems()[str];
    }
  
  
    if (isDeselecting) {
        if (id == dataItem._itemIndexHierarchical) {
            dataItem.set_selected(false);
            isDeselecting = false;
        }
        else
            id = dataItem._itemIndexHierarchical;
    }
    else if (isDeselecting == false) {
        id = dataItem._itemIndexHierarchical;
        isDeselecting = true;
    }
}

 My aspx Page is declared as followed.

<telerik:RadGrid ID="RadGridSubOrganizations" runat="server" BorderStyle="Solid" AllowFilteringByColumn="false"
 AutoGenerateColumns="false" Visible="true" Width="100%" OnItemCommand="RadGridSubOrganizations_ItemCommand"   
 Height="150px" OnDetailTableDataBind="RadGridSubOrganizations_DetailTableDataBind" 
 OnItemDataBound="RadGridSubOrganizations_ItemDataBound" SortingSettings-EnableSkinSortStyles="true" 
 MasterTableView-ExpandCollapseColumn-Display="true" AllowSorting="false" 
 ShowStatusBar="true" GridLines="None" HeaderStyle-BackColor="#BDBDBD">
  
<MasterTableView CellSpacing="-1" AllowNaturalSort="false" TableLayout="Fixed" Name="Organization" 
  DataKeyNames="ParentOrganizationId,ChildOrganizationId,SubChildOrganizationId"
  ItemStyle-BackColor="#B0C4DE" GridLines="None">                                                                                       
 <HeaderStyle CssClass="HeaderColor" /> 
  
 <DetailTables>
    <telerik:GridTableView DataKeyNames="ParentOrganizationId,ChildOrganizationId" Width="100%" 
    GridLines="None" HeaderStyle-BackColor="#BDBDBD" HeaderStyle-ForeColor="Black" ItemStyle-BackColor="#ADD8E6">                                                                                   
    <DetailTables>                                              
    <telerik:GridTableView DataKeyNames="ParentOrganizationId,ChildOrganizationId,SubChildOrganizationId" Width="100%" 
     ItemStyle-BackColor="#DEF3FA" GridLines="None" HeaderStyle-BackColor="#BDBDBD" HeaderStyle-ForeColor="Black">                                                                                                                          

When event comes to javascript function index of row is in variable eventArgs._itemIndexHierarchical.
But if Row in GridTableView is selected eventArgs._itemIndexHierarchical contains mystic index like: 1:0_0:0_0_0 and exception is thrown when trying to get dataItem from GridTableView. How should I reference to index? Couldn't find any samples or documentation considering this.

How to do this?

Br

Michael

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Feb 2011, 05:42 AM
Hello Mike,

If you want to get the selected data item in RowSelected event, try the following code snippet.

Java Script:
<script type="text/javascript">
       function RowSelected(sender, eventArgs) {
           var dataItem = eventArgs.get_gridDataItem();//getting selected row(in master/detail table)
    }
</script>

Thanks,
Princy.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or