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

Using RadDataFilter with VirtualQueryableCollectionView and WCF RIA Services

1 Answer 98 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajat Panwar
Top achievements
Rank 1
Rajat Panwar asked on 21 Oct 2012, 10:16 AM
Hello,

We have a scenario where we want to use VirtualQueryableCollectionView with RadDataFilter using WCF RIA Services.
What we have done is binding a radgridview to a VirtualQueryableCollectionView which is fetching Data from WCF RIA Service. We also need RadDataFilter to work along with it. Here is XAML
<Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MaxHeight="256"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <telerik:RadExpander telerik:StyleManager.Theme="Metro" Header="FILTER OPTIONS" FontFamily="/S4S.Reseller.Client;component/Fonts/Fonts.zip#Segoe UI" FontSize="16" Background="{x:Null}" BorderBrush="{StaticResource MetroBlue}" BorderThickness="1">
            <telerik:RadDataFilter Source="{Binding AccountsCollectionView}" telerik:StyleManager.Theme="Metro"/>
        </telerik:RadExpander>
        <telerik:RadGridView IsBusy="{Binding AccountsCollectionView.IsLoading}" AutoGenerateColumns="False" ItemsSource="{Binding AccountsCollectionView}" telerik:StyleManager.Theme="Metro" BorderBrush="{x:Null}" BorderThickness="0" ShowGroupPanel="False" IsReadOnly="True" IsFilteringAllowed="False" FontFamily="/Surf4Sure.Reseller.Client;component/Fonts/Fonts.zip#Segoe UI" FontSize="18.667" RowIndicatorVisibility="Collapsed" Grid.Row="1" IsSynchronizedWithCurrentItem="True" CanUserDeleteRows="False" CanUserInsertRows="False" ValidatesOnDataErrors="None" DataLoadMode="Asynchronous">              
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding AccountType}" Header="">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="{Binding AccountType, Converter={StaticResource AccountTypeToImagePathConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="56" Width="56"/>                               
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Account Id" DataMemberBinding="{Binding AccountId}" Width="*"/>
                    <telerik:GridViewDataColumn Header="Account Name" DataMemberBinding="{Binding AccountName}" Width="*"/>
                    <telerik:GridViewDataColumn Header="Primary Email" DataMemberBinding="{Binding PrimaryEmailAddress}" Width="*"/>
                    <telerik:GridViewDataColumn Header="Created On" DataMemberBinding="{Binding CreatedOn}" Width="*"/>
                    <telerik:GridViewDataColumn Header="Created By" DataMemberBinding="{Binding CreatedByName}" Width="*"/>
                </telerik:RadGridView.Columns>             
            <i:Interaction.Triggers>
                <S4S_Reseller_Client_Helpers:RadGridViewRowMouseDoubleClickTrigger>
                    <i:InvokeCommandAction Command="{Binding ShowAccountDetailsCommand}"/>
                </S4S_Reseller_Client_Helpers:RadGridViewRowMouseDoubleClickTrigger>
            </i:Interaction.Triggers>              
            </telerik:RadGridView>
 
    </Grid>


and this is our ViewModel code
public VirtualQueryableCollectionView AccountsCollectionView { get; private set; }
 
        private S4SDataContext dataContext = null;
        public AccountsListViewModel()
        {
            dataContext = new S4SDataContext();
 
            AccountsCollectionView = new VirtualQueryableCollectionView() { LoadSize = App.DefaultPageSize, VirtualItemCount = 10 };
            AccountsCollectionView.ItemsLoading += new EventHandler<VirtualQueryableCollectionViewItemsLoadingEventArgs>(AccountsCollectionView_ItemsLoading);
        }
 
        void AccountsCollectionView_ItemsLoading(object sender, VirtualQueryableCollectionViewItemsLoadingEventArgs e)
        {
            var accountsQuery = dataContext.GetAccountsQuery().IncludeTotalCount(true).Where(AccountsCollectionView.FilterDescriptors).OrderBy(o => o.AccountName).Sort(AccountsCollectionView.SortDescriptors).Skip(e.StartIndex).Take(e.ItemCount);
 
            dataContext.Load<Account>(accountsQuery).Completed += (querySender, args) =>
            {
                var loadOperation = (LoadOperation)querySender;
                if (loadOperation.TotalEntityCount != -1 && loadOperation.TotalEntityCount != AccountsCollectionView.VirtualItemCount)
                {
                    AccountsCollectionView.VirtualItemCount = loadOperation.TotalEntityCount;
                }
 
                AccountsCollectionView.Load(e.StartIndex, loadOperation.Entities);
            };
        }


Now everything is working fine except one issue. If I specify a filter which does not returns any result or we can say if loadOperation.TotalEntityCount is returned as 0, Then AccountsCollectionView_ItemsLoading does not fires anymore even if I remove that filter. Reason behind is VirtualItemCount is set to 0.
Is there any event or some way so that I can get to know when user modifies filters in RadDataFilter or any way I can get this to work.

Thanks and Regards,
Rajat Panwar

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Oct 2012, 02:19 PM
Hello,

You could subscribe to the ItemChanged event of the FilterDescriptors collection. It will be fired for every possible change - no matter how deep in the hierarchy it happened.

Then you could review the code for the  Data Virtualization demo on how the data is updated when the filtering criteria has changed. 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DataFilter
Asked by
Rajat Panwar
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or