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

Accessing selected row in nested radgrid on client

5 Answers 396 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Raka
Top achievements
Rank 1
Raka asked on 07 Jun 2013, 12:32 PM
Hi

We have a radgrid with one level nested grid.  When the grid is built on server side, we have some logic which allows a row in nested grid to get selected (in ItemDataBound event handler).  Code looks something like --

protected void rgGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.ItemType = GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
    {
        ...
        if (<something is true>) e.Item.Selected = true;
    }
}

The grid has a menu and when one of the buttons is clicked on it, we want to send the seleted item info to the popup from client side.
So the grid has a client side function like -
function rmuGridClientItemClicked(sender, args)
{
    return OpenWindow(url + "?SelectedItem=" + selectedItemId);
}

How do we get the selectedItemId?  I have tried using
var radGrid = $find("<%= rgGrid.ClientID %>");
var MasterTable = radGrid.get_masterTableView();
var row = MasterTable.get_dataItems();
var item1 = row[0].get_nestedViews()[0].get_selectedItems();

but get_selectedItems always returns empty array.

I think that it is because the item is getting selected on server but I am accessing it in JS code. 
Can someone suggest a way to do this the right way?

Thanks
Raka

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Jun 2013, 02:24 PM
Hi,

Please try the following code to access the selected rows via client side.

JS:
function Click()
{
   var grid = $find("<%=RadGrid1.ClientID %>");
   var MasterTable = grid.get_masterTableView();
     // to get the selected rows of master table
   var length = MasterTable.get_selectedItems().length;
   for (var i = 0; i < length; i++)
    {
    var id = MasterTable.get_selectedItems()[i].get_id();
    alert(id);
   }
   // to get the selected rows of detail table
   var dataItems = MasterTable.get_dataItems();
   for (var i = 0; i < dataItems.length; i++)
    {
    if (dataItems[i].get_nestedViews().length > 0)
       {
      var _id= dataItems[i].get_nestedViews()[0].get_selectedItems()[0].get_id();
      alert(_id);
    }
   }        
}

Hope this will help you.

Thanks
Princy
0
Raka
Top achievements
Rank 1
answered on 12 Jun 2013, 11:29 AM
Hello Princy

Thank you very much for your reply.
It sort of goes in the direction of what I need and is very close.
What I need is the DataKeyValue of the nested grid.

So, dataItems[0].getDataKeyValue("ParentKey") gives me the correct key value for the parent table.
What I need to get is the cell value for a specific column from the selected row in the nested grid.

How do I do that?

Thanks
Raka
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2013, 01:40 PM
Hi,

This is a code i tried it access the cell selected by the column UniqueName.Try editing accordingly.Have a look into these documentations for reference.
Accessing table views in a hierarchical grid
Cell-Selection

JS:
function Click() {
var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var selectedrow = MasterTable.get_selectedItems();
        var length = MasterTable.get_selectedItems().length;
        for (var i = 0; i < length; i++) {
            var id = MasterTable.get_selectedItems()[i].get_id();
            var cell = MasterTable.getCellByColumnUniqueName(selectedrow[i], "CustomerID");       
            alert(cell.innerHTML);
        }
        var dataItems = MasterTable.get_dataItems();
        for (var i = 0; i < dataItems.length; i++) {
            if (dataItems[i].get_nestedViews().length > 0) {
                var cell = dataItems[i].get_nestedViews()[0].get_selectedItems()[0].get_cell("OrderID");
                alert(cell.innerHTML);
            }
        }         
    }

Thanks,
Princy
0
Raka
Top achievements
Rank 1
answered on 14 Jun 2013, 03:41 PM
Thanks Princy.
Unfortunately for some reason, it is not registering the selected row in nested view.  So,
dataItems[i[.get_nestedViews()[0].get_selectedItems() is null.
The only time get_selectedItems is populated is if I am selecting the parent row :-(


===========
I have finally gotten the datakey value from selected row with the following code. But it is very poor code.  Is there an elegant way to do this?

 

 

for (var i = 0; i < rows.length; ++i) {

 

 

 

    var obj = $find(MasterTable.get_dataItems()[i].get_nestedViews()[0].get_element().id).get_parent().get_parent()._selectedIndexes;

 

    document.all($find(MasterTable.get_dataItems()[i].get_nestedViews()[0].get_element().id).get_parent().get_parent()._selectedItemsInternal[0].id).cells[2];

 

 

 

 

    if (obj != null && obj.length > 0)

 

        document.getElementById(

 

"hidSelected").value = obj.innerHTML;

 

 

 

}

Thanks
Raka

 

0
abdul qadar
Top achievements
Rank 1
answered on 08 Apr 2014, 05:19 AM
Thanks Princy,

You has given a good idea how to get selected items for detail table.

I want it further drilled down,
       Can I get the selected Items for expanded detail table only?

Any help is highly appreciated.

Thanks,
Abdul
Tags
General Discussions
Asked by
Raka
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Raka
Top achievements
Rank 1
abdul qadar
Top achievements
Rank 1
Share this question
or