Accessing selected row in nested radgrid on client

6 posts, 0 answers
  1. Raka
    Raka avatar
    71 posts
    Member since:
    Sep 2011

    Posted 07 Jun 2013 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Jun 2013 Link to this post

    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
  3. Raka
    Raka avatar
    71 posts
    Member since:
    Sep 2011

    Posted 12 Jun 2013 Link to this post

    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
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Jun 2013 Link to this post

    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
  5. Raka
    Raka avatar
    71 posts
    Member since:
    Sep 2011

    Posted 14 Jun 2013 Link to this post

    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

     

  6. abdul qadar
    abdul qadar avatar
    1 posts
    Member since:
    Nov 2009

    Posted 08 Apr 2014 in reply to Princy Link to this post

    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
Back to Top