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

Grouping and paging on collapse

3 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc-Andre
Top achievements
Rank 1
Marc-Andre asked on 11 Jan 2009, 09:55 PM
Hi,

Say a grid has a page size of 10. A datasource containing 20 items is bound to the grid and grouped on a given column. The grouping yields 2 groups of 10 elements. By default, only the first group is shown on the first page after the initial load.

On collapse of both groups, I would expect only 1 page of data showing the two collapsed groups. Currently, it seems like paging and grouping are dissociated in the grid even though they should complement each other.

I've seen many threads on grouping and paging and the general solution (without any source code) is to change the paging dynamically. Anyone has done it?

To do this, one would have to know what group is being collapsed/expanded, how many items are in this group and adjust the number of pages, the current page etc. and adjust the paging so that the current page contains all the grouped items collapsed into one plus the number of other items up to the page size. Not sure it's even possible to have different page size in the same grid. Sounds very hard indeed.

Any help is appreciated,

Marc-André Gosset

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 13 Jan 2009, 11:48 AM
Hi Marc-Andre,

Indeed, in such a case, the grouping will span over the two pages. The reason for this is that regardless of whether the groups are expanded or collapsed, the paging is based on the items contained within the groups. Thus, changing the pagesize dynamically  in this case is a nice approach.
You can set server expand collapse for the groups, and attach to the ItemCommand event handler, which will be raised when you expand/collapse a group. There, you can alter the page size.
I hope this suggestion helps.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Marc-Andre
Top achievements
Rank 1
answered on 13 Jan 2009, 04:13 PM
Thanks for your answer,

Could you provide some insight on how to determine the number of elements in the group that is expanded/collapsed?

0
Shinu
Top achievements
Rank 2
answered on 14 Jan 2009, 05:15 AM
Hi,

Try the following code snippet to get the number of items in a Group on Expand/Collapse.

CS:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "ExpandCollapse"
        { 
            GridGroupHeaderItem GroupHeader = (GridGroupHeaderItem)e.Item; 
 
            GridItem[] children = GroupHeader.GetChildItems(); 
            int childCount = children.Length; 
        } 
    } 


Thanks
Shinu.
Tags
Grid
Asked by
Marc-Andre
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Marc-Andre
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or