Telerik blogs

With our upcoming service pack (Q3 SP2) of RadGridView for Silverlight all operation like sorting, grouping and paging on the server can be achieved completely codeless when the grid is bound to DomainDataSource and in my previous post I’ve showed how to do the same for filtering with minimum code. You can even force the grid vertical scrollbar to page on the server instead DataPager.

Since WCF RIA services is still in beta I’ve made small example how to achieve sorting, grouping, paging and filtering using custom web service:

XAML

<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
<
Grid x:Name="LayoutRoot">
<
Grid.RowDefinitions>
<
RowDefinition />
<
RowDefinition Height="Auto" />
</
Grid.RowDefinitions>
<
telerik:RadGridView AutoExpandGroups="True" ItemsSource="{Binding Data}"
DistinctValuesLoading="RadGridView1_DistinctValuesLoading" />
<
data:DataPager Source="{Binding Data}" Grid.Row="1" />
</
Grid>
</
UserControl>


C#

using System.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Data;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
{ public MainPage() { InitializeComponent(); DataContext = new MyDataContext(); } void RadGridView1_DistinctValuesLoading(object sender, GridViewDistinctValuesLoadingEventArgs e) { var client = ((MyDataContext)DataContext).Client; var collection = new RadObservableCollection<object>(); e.ItemsSource = collection; client.GetDistinctValuesCompleted += (s, args) => { collection.Clear(); collection.AddRange(args.Result); }; client.GetDistinctValuesAsync(e.Column.UniqueName); } } }


The result:
image 

The grid expressions are transferred as strings (I’ve made several extension methods available in DescriptorsExtensions.cs) and on the server-side these string expressions are used in a custom LinqDataSource in order to handle all operations on the data-base server.

You can check also MyDataContext.cs to know more about how to create your own QueryableCollectionView to handle such advanced custom scenario where you need to handle paging, grouping, sorting and filtering by yourself.

Enjoy!


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.