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

Server-side paging, sorting and grouping

14 Answers 350 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 10 Jun 2010, 01:44 PM
Hi

I've been reading Vladimir's blog about how to achieve server-side paging, etc. and have managed to get it working as expected apart from Grouping...
 
As an example I've got 20 items in my resultset and have set a page size of 10. If I group by a field called country (which has 2 distinct values) I would like to see Country 1 (which when expanded would show 8 items) and Country 2 (when expanded 2 items). The remaining Country 2 items would then be displayed on page 2. This is how the SL4 domain data source example works. Unfortunately in my test application when I group by the field, I get a single page back with both grouped countries however all rows are being brought back to the client i.e. the paging is working on the group level rather than the item level.

Can you please give me some indication of how I can change the code in Vladimir's blog to achieve the required grouping behaviour?

Thanks
Keith

14 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 14 Jun 2010, 01:39 PM
Hello Keith Pilkington,

I have modified Vlad's example to behave as you are expecting. The grouping is only executed on the client side similarly to the DomainDataSource behavior. Please feel free to modify the attached code if you want to extend this example further.

Hope this helps,
Stefan Dobrev
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.
0
Keith
Top achievements
Rank 1
answered on 15 Jun 2010, 04:06 PM
Thanks Stefan, I'll take a look.
0
Ken
Top achievements
Rank 1
answered on 17 Sep 2010, 06:38 PM
Hi Stefan,

I tried to use your example in my app. However, there's something strange going on: the first time the data is loaded into the gridview, the "x_CollectionChanged" method is called by the gridview, triggering in effect a second loading of the data. So the data is basically loaded twice everytime the page is loaded.

The callstack is this:
     Telerik.Windows.Data!Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) + 0x85 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.QueryableCollectionView.RefreshOverride() + 0x545 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.QueryableCollectionView.RefreshInternal() + 0x23 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer() + 0x4a bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh() + 0x21 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.QueryableCollectionView.OnGroupDescriptorsCollectionChanged(object sender = Count = 0, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) + 0x2c bytes   
     System.Windows.dll!System.Collections.ObjectModel.ObservableCollection<Telerik.Windows.Data.IGroupDescriptor>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x37 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.RadObservableCollection<Telerik.Windows.Data.IGroupDescriptor>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) + 0x38 bytes   
     System.Windows.dll!System.Collections.ObjectModel.ObservableCollection<System.__Canon>.ClearItems() + 0x8b bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.RadObservableCollection<Telerik.Windows.Data.IGroupDescriptor>.ClearItems() + 0x14f bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.ObservableItemCollection<Telerik.Windows.Data.IGroupDescriptor>.ClearItems() + 0x34b bytes   
     mscorlib.dll!System.Collections.ObjectModel.Collection<Telerik.Windows.Data.IGroupDescriptor>.Clear() + 0x40 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.CollectionHelper.Equalize(System.Collections.IList left = Count = 0, System.Collections.IList right = Count = 0) + 0xee bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.DataItemCollection.EqualizeGroupDescriptors() + 0x9d bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.DataItemCollection.EqualizeDescriptors() + 0x33 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.DataItemCollection.CollectionView.set(Telerik.Windows.Data.QueryableCollectionView value = {CoreSystems.BusinessClient.Silverlight.Common.Collections.CustomQueryableCollectionView}) + 0x11c bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.DataItemCollection.CreateCollectionView(System.Collections.IEnumerable source = {CoreSystems.BusinessClient.Silverlight.Common.Collections.CustomQueryableCollectionView}) + 0x85 bytes   
     Telerik.Windows.Data!Telerik.Windows.Data.DataItemCollection.SetItemsSource(System.Collections.IEnumerable source = {CoreSystems.BusinessClient.Silverlight.Common.Collections.CustomQueryableCollectionView}) + 0xce bytes   
     Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewDataControl.Bind.AnonymousMethod__47() + 0x25c bytes   
     Telerik.Windows.Controls!Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(System.Windows.FrameworkElement frameworkElement = {Telerik.Windows.Controls.RadGridView}, System.Action action = {System.Action}) + 0x74 bytes   
     Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(object newValue = {CoreSystems.BusinessClient.Silverlight.Common.Collections.CustomQueryableCollectionView}) + 0x87 bytes   
     Telerik.Windows.Controls.GridView!Telerik.Windows.Controls.GridView.GridViewDataControl.OnApplyTemplate() + 0x3f5 bytes   
     System.Windows.dll!System.Windows.FrameworkElement.OnApplyTemplate(System.IntPtr nativeTarget) + 0x5b bytes   

Note: this behavior does NOT happen with the code you attached. I guess it happens to me because I'm using a newer version of the telerik binaries, e.g. in your code Telerik.Windows.Data has version 2010.1.422.1040, while I'm using 2010.2.827.1040.
Note 2: in my code I also have a group descriptor added to the queryable collection. But I also added one in your sample code, so they're the same, but it still doesn't show this behavior, I guess because of the older version of the telerik binaries...

Do you have any suggestion how to get around this issue?

Thanks!
0
Stefan Dobrev
Telerik team
answered on 20 Sep 2010, 08:38 AM
Hello Adrian,

I have just updated this sample to use the binaries you are using - 2010.2.827.1040. I have placed a breakpoint in CollectionChanged handler but it is stopping exactly once in my application. Are you doing same extra work in your application? It would be best if you could send us your application that reproduces this wrong behavior. Using it we will be able to debug the problem locally and provide you with a solution.

All the best,
Stefan Dobrev
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
0
Ken
Top achievements
Rank 1
answered on 20 Sep 2010, 12:41 PM
Hi Stefan,

You can download a repro here: http://cid-5a652c421a7d71ae.office.live.com/self.aspx/telerik/RadDataPagerRepro.zip

Probably I'm doing something wrong, but for me the breakpoint in the businessPartners_CollectionChanged method is getting hit twice when I start the application (once it seems to clear the group descriptors collection and once when it re-adds the group descriptor to it).

Any hints are appreciated

Thanks,
Adrian
0
Stefan Dobrev
Telerik team
answered on 23 Sep 2010, 03:22 PM
Hi Adrian,

The problem in your case is the group descriptor that is added in your CollectionView. When RadGridView is bound to a QueryableCollectionView it equalizes all its descriptors with its source collection view descriptors. This operation causes this extra collection changed that you are observing. My suggestion is to set this descriptor in XAML like this:
<telerik:RadGridView
                    ItemsSource="{Binding PagedSource, ElementName=pager}"
                    IsReadOnly="True"
                    ShowGroupPanel="False"
                    ShowColumnHeaders="False"
                    RowIndicatorVisibility="Collapsed"
                    AutoGenerateColumns="False"
                    AutoExpandGroups="True"
                >
    <telerik:RadGridView.Columns>
        <telerik:GridViewColumn Width="*" CellTemplate="{StaticResource ListItemTemplate}"/>
    </telerik:RadGridView.Columns>
    <telerik:RadGridView.GroupDescriptors>
        <telerik:GroupDescriptor Member="NameFirstLetter" />
    </telerik:RadGridView.GroupDescriptors>
</telerik:RadGridView>

Will this work for you?

Greetings,
Stefan Dobrev
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
0
Ken
Top achievements
Rank 1
answered on 27 Sep 2010, 07:59 AM
Hi Stefan,

With your suggestion the collectionchanged handler still gets hit once. Is there a way to not have it hit at all? Because actually when it gets hit I do a reload of the data (because I don't know, in the handler, WHY it got hit...so as to not do a reload of data if it was called because of grouping stuff, and only do a reload if it was called because of paging to another page).

Thanks,
Adrian
0
Stefan Dobrev
Telerik team
answered on 27 Sep 2010, 09:21 AM
Hello Adrian,

You will have to use GroupDescriptors.CollectionChanged event in order to achieve this. You will disable the refresh when a group descriptor is added or removed in order to avoid the server call.

Regards,
Stefan Dobrev
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
0
3CON Consultoria e Sistemas LTDA
Top achievements
Rank 1
answered on 04 Mar 2011, 03:58 PM
Guys,

I made some changes in your code to use POCO.
On the first time, with no grouped columns, the grid populates correctly.
My problem is when I try to group by some column.
The data is returning correct from the server but I'm getting an InvalidCastException to type 'Telerik.Windows.Data.IGroup' on binding to grid.
I'm attaching the error's printscreen.
Do you have any suggestion how to get around this error?

Best regards,
Henrique
0
Yavor Georgiev
Telerik team
answered on 06 Mar 2011, 01:02 AM
Hi Henrique,

 Could you please open a separate support ticket and attach your application so that we can debug it? Thank you.

All the best,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
David
Top achievements
Rank 1
answered on 25 May 2011, 05:06 PM
I'm actually interested in getting the pager working with server side grouping.  Currently I have set two group desciptors on a Ria DomainDataSource, but when I set page size on the RadDataPager, it selects that number of items from the server, not number of groups.  Therefore, in the RadDataGrid, the groups are split across pages.

Is there a way to get the number of groups for page size instead of records, so you don't have the groupings split across pages?

thx.
0
Vlad
Telerik team
answered on 26 May 2011, 06:55 AM
Hi,

This is just how WCF RIA Services will group - a bit fake since they will execute OrderBy instead GroupBy.

Greetings,
Vlad
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
0
David
Top achievements
Rank 1
answered on 26 May 2011, 04:22 PM
Hey Vlad, thanks for getting back.

When it is grouped on the server (ordered) via the DomainDataSource, is there a way to page from the grouping?  If I set page size to say 100 on the Rad Pager, I get 100 records, not 100 groups.  This causes some of the groupings to be split across successive pages, which is not desirable in my case.

thanks,
david.
0
Rossen Hristov
Telerik team
answered on 26 May 2011, 04:28 PM
Hello,

That is the intended behaviour and cannot be changed.

Paging is done on the server, while grouping is done later on the client when these 100 records have already arrived. You can think of this as of a RadGridView which has an ItemsSource with exactly 100 items and is then grouped.

There is nothing that can be done about this. Furthermore, WCF RIA Services do not have the ability to group, i.e. they always return Entities.

I hope this helps.

Best wishes,
Ross
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
GridView
Asked by
Keith
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Keith
Top achievements
Rank 1
Ken
Top achievements
Rank 1
3CON Consultoria e Sistemas LTDA
Top achievements
Rank 1
Yavor Georgiev
Telerik team
David
Top achievements
Rank 1
Vlad
Telerik team
Rossen Hristov
Telerik team
Share this question
or