Programatically colapse / expand groups

8 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 29 Mar 2013 Link to this post

    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
  2. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 03 Apr 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 08 Apr 2013 Link to this post

    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
     
  5. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 12 Apr 2013 Link to this post

    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.
  6. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 14 Apr 2013 Link to this post

    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
  7. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 17 Apr 2013 Link to this post

    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.
  8. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 18 Apr 2013 Link to this post

    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
  9. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 23 Apr 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017