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

Client Side expand/collapse of group

1 Answer 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 25 Jun 2010, 08:09 PM
There is really no documentation to speak of on the Radgrid OnGroupExanded and OnGroupCollapsed client events so I'm hoping I can get some help from the community.

Scenario: I have Client Side Grouping set on a grid and I need to be able to persist what groups were expanded/collapsed between rebinds so I can't use server side itemcommand event because nothing fires sever side when you use client side grouping.

Approach: I am attaching two javascript functions to handle the two different events and fire a ajaxRequest to the server side with the index of the row expanded/collapsed. I have all the server side hash tables set up based on a forum example and will use the grid.item[itemIndex].expanded = true or false to rehydrate on page load.

Problem: I don't know how to get anything from the two client events to determine what item index was expanded/collapsed. The eventArgs are supposed to be a gridDataItem object but I've had no success accessing properties.

Question: How do I get the index of the expanded/collapsed row client side? See below javascript function.

function

 

CollapseGroup(sender, eventArgs) {

 

var itemIndex = eventArgs (what to do here?)

 

 

$find(

 

"ctl00_RadAjaxManager1").ajaxRequest("Collapsed~" + itemIndex);

 

}

 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 01 Jul 2010, 12:59 PM
Hello Sean,

Unfortunately this is not supported by default. However you may achieve this by using the following script:

 <script type="text/javascript">                        
      function groupCollapsed(sender, args) {
          var grid = $find(sender.get_id());
          var expandedGroupItems = grid._expandedGroupItems;
          var lastItemId = expandedGroupItems[expandedGroupItems.length - 1 ];                                
          alert("Owner TableView: " + lastItemId.split('!')[0]);
          alert("Table Row Index : " + lastItemId.split('!')[1]);                
      }
  </script>

Then you can get the GroupHeaderItem on the server as following:

private GridGroupHeaderItem GetGroupHeaderItem(string tableViewId, string rowIndex)
{        
    GridTableView view = (GridTableView)Page.FindControl(tableViewId);
    if (view != null)
    {
        Table table = view.Controls[0] as Table;
        TableRow row = table.Rows[int.Parse(rowIndex)];
        if (row is GridGroupHeaderItem)
        {
            return (row as GridGroupHeaderItem);                
        }
    }
    return null;
}


All the best,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Sean
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or