Server sorting and filtering with WCF RIA Services and Telerik Data Virtualization for Silverlight

by Vladimir Enchev | Comments 18

I’m happy to announce that with our upcoming service pack (Q3 2010 SP1) you will be able to sort, filter and load records on demand with WCF RIA Services and our VirtualQueryableCollectionView.
image

 

To enable this we’ve added two extension methods for EntityQuery<T> and now you can use directly VirtualQueryableCollectionView SortDescriptors and FilterDescriptors:

var context = new NorthwindDomainContext();
var query = context.GetOrder_DetailsQuery().OrderBy(o => o.OrderID);

var view = new VirtualQueryableCollectionView() { LoadSize = 10, VirtualItemCount = 100 };
view.ItemsLoading += (s, e) =>
{
    var queryToLoad = query
.IncludeTotalCount(true)
.Sort(view.SortDescriptors)
.Where(view.FilterDescriptors)
.Skip(e.StartIndex)
        .Take(e.ItemCount);

    context.Load<Order_Detail>(queryToLoad).Completed += (sender, args) =>
    {
        var lo = (LoadOperation)sender;
        if (lo.TotalEntityCount != -1 && lo.TotalEntityCount != view.VirtualItemCount)
        {
            view.VirtualItemCount = lo.TotalEntityCount;
        }

        view.Load(e.StartIndex, lo.Entities);
    };
};
 

Enjoy!

 

,
Senior Technical Architect

18 Comments

Rob
Very cool! Now, when can we have SP1?
Vlad
Hi Rob,

Our service pack will be next week.

Vlad
Charlie
Ok.  It is now next week.  When can we actually get SP1?

Thanks,

Charlie J.
Charlie
I see that the SP1 has been delayed until Mid/Late Jan. 2011.  Does the latest internal build contain the assemblies for Silverlight for this example to run again?

Charlie J.
Mitch
Hi Vlad

Can you check that your example still works with RadGridView for Silverlight 2011.1

When I try to run your example, .Sort and .Where don't seem to be available.

If I run your example without the Sort and Where it runs fine.

Is there something I am missing?

Mitch
Vlad
Hi Mitch

These methods are part of Telerik.Windows.Controls.DomainServices.dll. They are extension methods located in Telerik.Windows.Controls.DomainServices namespace (EntityQueryExtensions class). 

Vlad
Mitch
Hi Vlad

Thanks for your help, it's now working.

Just a couple of additonal questions.

I've noticed that the column filter only shows values that are loaded, not all the values for the column. For instance, a column displaying Countries would have UK, USA, France, Holland etc, but would only show UK and USA in the filter if they were the only ones initially loaded. The others would only be shown if you paged through the records. How do you overcome this.

Also, is there an example of using WCF RIA Services and Telerik Data Virtualization for Silverlight with the RadDataFilter?

Many thanks

Mitch
Denis
Small fix:



view.VirtualItemCount = lo.TotalEntityCount;

if (view.VirtualItemCount == 0)

{

  view.VirtualItemCount = 100;

}

When I'm filtering the grid and no results are returned, 'Clear Filter' doesn't work without reseting VirtualItemCount to a value greater than zero.

Michael
Hi!
Great article, i was wondering if there is a way to do a serverside grouping as well.Tried it but i keep getting exceptions, tried it this way:
var queryToLoad = query
.IncludeTotalCount(true)
.Sort(view.SortDescriptors)
.Where(view.FilterDescriptors)
.GroupBy(view.GroupDescriptors)
.Skip(e.StartIndex)
.Take(e.ItemCount);
Vlad
Hi Michael,
Unfortunately server-side grouping in Silverlight version of the collection is not supported.
Michael
Ok, thanks a lot!
I'm using your approach in a WPF application, is there a way for grouping?
Denis
Sorry, my fix is incorrect. Please don't use the previous version of it.
The correct version is:

var queryableView = new VirtualQueryableCollectionView<...>
            {
                LoadSize = 10,
                VirtualItemCount = 100
            };

   queryableView.FilterDescriptors.CollectionChanged += (s, e) =>
   {
    if (queryableView.FilterDescriptors.Count == 0)
    {
     queryableView.VirtualItemCount = 100;
    }
   };

Shiva Wahi
May I please know how can we apply sorting and filtering in WCF. We are not using WCF RIA Services so cannot use below code.

EntityQuery

 

 

<Customer> query = Context.GetCustomersQuery();

 

query.IncludeTotalCount =

 

true;

 

query = query

.Sort(Customers.SortDescriptors)

.Where(Customers.FilterDescriptors)

.Skip(e.StartIndex)

.Take(e.ItemCount);

Context.Load<

 

Customer>(query, LoadBehavior.RefreshCurrent, CustomersLoaded, e.StartIndex);

 

Remco Blok
Would it be possible to make those Sort and Where extension methods on EntityQuery also available on QueryBuilder?QueryBuilder as found in Microsoft.Windows.Data.DomainServices.dll in the WCF RIA Services Toolkit (April 2011 or later) or the RIAServices.MVVM NuGet package. That way we don't have to work with EnityQuery and LoadOperation in our view model. See http://blogs.msdn.com/b/kylemc/archive/2011/04/29/mvvm-pattern-for-ria-services.aspx.
many thanks
Remco Blok
Never mind my comment. Microsoft.Windows.Data.DomainServices
also contains CollectionViewExtensions and since VirtualQueryableCollectionView implements ICollectionView I can call the SortBy extension method on QueryBuilder passing in the VirtualQueryableCollectionView.
Remco Blok
That leaves a Where extension method on QueryBuilder that does not exist.
Christian
Hi Vlad,
Right now,  is supported server-side grouping in Silverlight?
I'm using VirtualQueryableCollectionView, but when I try to group, the grid shows an empty group label with many empty items, actually, after group the data disappear (grid shows many empty rows)

 


Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by Vladimir Enchev - or - read latest articles in Developer Tools


Follow vladimir_enchev on Twitter