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

Programatically colapse / expand groups

7 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 29 Mar 2013, 09:32 AM
Hi

I have a grid with Grouping and GroupsDefaultExpanded="false"  to colaspe the groups when the grid loads.

In each group section I have checkboxes to allow users to make selections, what I want to do is when the user re opens the grid, those groups that have previously had a selection made are not colapsed,

Or some other way to let the user know which group has selections made.

Andy

7 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 Apr 2013, 07:24 AM
Hello Andy,

You can combine the logic from these two articles to implement the requested functionality:
http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-client-sorting-paging-grouping-filtering.html
http://www.telerik.com/community/code-library/aspnet-ajax/grid/persist-groups-expanded-state-on-rebind.aspx

Hope this helps.

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Andy Green
Top achievements
Rank 2
answered on 08 Apr 2013, 11:50 AM
Thanks Eyup

I'm not looking to persist over a post back, I have this in a database. I have changed my stored proc to have a flag of Expanded, for the group, I'm having trouble as to where to do this.

In my itemdatabound I can expand / collapse all rows based  on a flag (1 or 0) but I cant get it to do it using my data flag.

Are there any more examples using my particular requirement.

Andy
 
0
Eyup
Telerik team
answered on 12 Apr 2013, 01:48 PM
Hello Andy,

For example, if the grid is grouped by ShipCountry, you can use the following approach:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridGroupHeaderItem)
    {
        GridGroupHeaderItem groupHeader = e.Item as GridGroupHeaderItem;
        DataRowView dataItem = groupHeader.DataItem as DataRowView;
 
        if (dataItem["ShipCountry"].ToString() == "Austria")
        {
            groupHeader.Expanded = true;
        }
        else
        {
            groupHeader.Expanded = false;
        }
    }
}

Additionally, you can use templates and determine the expanded state of the group header corresponding to a control content within the template:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/headerandfootertemplates/defaultcs.aspx

Hope this helps.

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Andy Green
Top achievements
Rank 2
answered on 14 Apr 2013, 03:37 PM
Hi Eyup

Nearly, except I'm not comparing to a string, I'll be comparing to a field in my database. If I replace the sting (Austria) with my data value dataItem["ExpandedGroup"] I keep getting the error  ExpandedGroup is neither a DataColumn nor a DataRelation for table GroupedTable0. THis is because I'm not grouping on ExpandedGroup, and it not in the Groupomg section of the grid markup/

I have tried several things but can't get things to work

Andy
0
Eyup
Telerik team
answered on 18 Apr 2013, 04:47 AM
Hello Andy,

In that case, you will need add the field using a template as demonstrated in the provided link in my previous post, or preserve the corresponding value on a ViewState or Session variable and use it during the ItemDataBound event handling for the GridGroupHeaderItem.

Hope this helps. If you need further assistance, please elaborate on how you are getting the condition value or send us a very basic runnable sample demonstrating your specific scenario. Thus, we will be able to further analyze the requirement and suggest a more-to-point approach.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Andy Green
Top achievements
Rank 2
answered on 18 Apr 2013, 07:01 AM
Thanks, I'll go though it all again.

This is holding me up now so have to get it sorted today.

In essence you previous code example worked :

if (dataItem["ShipCountry"].ToString() == "Austria")

but I don't have the string to compare to, its another database field that tells me whether to expand or not.

if (dataItem["ShipCountry"].ToString() == dataItem["Expanded"].ToString())

and the 'Expanded' data field doesn't exist in the grouping section/.


I'm not able to use the viewstate or session as when the page loads for the first time, the 'Expanded' data is in the database, not in any postback data and not in any fixed string.

Thanks for your help so far.

Andy
0
Eyup
Telerik team
answered on 23 Apr 2013, 10:06 AM
Hi Andy,

As I explained in my previous post, we will need detailed information about your specific scenario to be able to assist you further. Please open a support ticket and send us a runnable isolated version of your project along with a sample datasource.

Thank you for your cooperation in advance.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Andy Green
Top achievements
Rank 2
Share this question
or