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

[Solved] How do I bind a GridView and Pager to a domain data source entirely from code?

5 Answers 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jean
Top achievements
Rank 1
Jean asked on 20 Aug 2010, 03:00 PM
Hi, I'm relatively new to the Telerik Components, but so far they've been great, and very useful.

We're currently using a GridView and a pager to query a DomainDataSource and show it on screen, using paging.


<telerik:RadGridView x:Name="ResultsGrid" Grid.Row="3" Grid.Column="0" 
                                 Grid.ColumnSpan="3"
                                 Grid.RowSpan="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                 AutoGenerateColumns="True" ScrollMode="Deferred"
                                 ItemsSource="{Binding Source={StaticResource ExampleDomainService},Path=Data}"
                                 telerik:StyleManager.Theme="Windows7"
                                 AutoExpandGroups="True"
                                 >
          
 
        </telerik:RadGridView>
            <telerik:RadDataPager Grid.Row="4" Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="radDataPager1" VerticalAlignment="Top"
                                  Source="{Binding Source={StaticResource ExampleDomainService},Path=Data}"
                                  telerik:StyleManager.Theme="Windows7"/>

We then have the following code in App.xaml

<ria:DomainDataSource x:Key="ExampleDomainService" QueryName="GetISCOMPETITIONRESULTTABLEs" AutoLoad="True" PageSize="10" >
       <ria:DomainDataSource.DomainContext>
            <services:ExampleDomainContext/>
       </ria:DomainDataSource.DomainContext>
</ria:DomainDataSource>

So far this works great. We also noticed that it gets data asynchronously.

However, we wish to try getting data from the datacontext and applying it to both the pager and the gridview entirely via code.

So far, we have the following:

ctx = new ExampleDomainContext();
                     
LoadOperation<Example> loadOp = ctx.Load(ctx.TakeTopNQuery(100));
 
PagedCollectionView view = new PagedCollectionView(loadOp.Entities);
view.PageSize = 10;
ResultsPager.Source = view;
ResultsPager.IsTotalItemCountFixed = true;
ResultsGrid.ItemsSource = ResultsPager.PagedSource;

This works well for small queries, such as getting the top 100 records, but we can no longer fetch the entire table asynchronously. Is there a way to do this in code?

Thanks.

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 20 Aug 2010, 03:08 PM
Hello Jean,

Fetching the entire amount of data on the client will defeat the whole idea of paging.
If you do not want to use the DomainDataSource control, then you can use RadDataPager in its Unbound Mode which was introduces as a feature last week.

When in Unbound Mode, the pager does not have a Source. Only when you are in Unbound Mode you can set its ItemCount property to the total number of items that you want. Then you will be using the pager for its UI only. You will attach to the PageIndexChanged event of the pager. Inside the handler you will receive the page index that the user has selected. Having this page index you can call your service and get this page of data and then assign it as the ItemsSource of the grid.

Your other option is to let the DomainDataSource control do all of this stuff for you.

I hope this helps.

P.S. For the Unbound Mode feature you will need to get the 2010 Q2 SP1 version.

Kind regards,
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
0
Jean
Top achievements
Rank 1
answered on 20 Aug 2010, 03:14 PM
Hi, thanks for your answer.

Perhaps I didn't express myself well enough.

With the components defined in XAML, we were able to look at the entire table (22000 rows, divided into 2000 pages) because the pager was probably fetching data on demand. 

We wish to replicate that behaviour but without using XAML. We don't wish to view the entire table at one go, we still wish to use the pager. But as I said in my previous question, the pager seems to be eagerly fetching all the data before it displays it.

Thanks.
0
Rossen Hristov
Telerik team
answered on 20 Aug 2010, 03:25 PM
Hello Jean,

The pager is neither fetching data nor displaying it. Can you please remove the pager from the whole picture and see what is going on.

By the way -- what is the problem of creating a DomainDataSource control in code? Do it an use the control instead of using the context.

Greetings,
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
0
Rossen Hristov
Telerik team
answered on 20 Aug 2010, 03:27 PM
Hi Jean,

I have an even better suggestion -- replace RadDataPager with the MS DataPager and see what will happen. If the results are different -- please open a separate support ticket, prepare a sample project that reproduces this behavior and send it to us. We will debug it and see what is going on.

Thank you for your understanding.

Regards,
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
0
Jean
Top achievements
Rank 1
answered on 23 Aug 2010, 03:01 PM
Hi Ross, I'm pleased to report that I managed to fix this issue by using the completed event of the LoadOperation.
Tags
GridView
Asked by
Jean
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Jean
Top achievements
Rank 1
Share this question
or