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

Get sorted source

5 Answers 61 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Krzysztof
Top achievements
Rank 1
Krzysztof asked on 08 Jun 2015, 08:37 AM

Hi,

 
I'm using RadDataPager with RadGridView. I need to access sorted source in RadDataPager after click on column header of my RadGridView.

Below is my code:

 
<telerik:RadGridView ItemsSource="{Binding PagedSource, ElementName=pager}" CanUserSortColumns="True" AutoGenerateColumns="True" />

<telerik:RadDataPager x:Name="pager" PageSize="25" Source="{Binding RecordsItemsSource}"
 IsTotalItemCountFixed="False"
 DisplayMode="All"
 NumericButtonCount="10" />

 
Where RecordsItemsSource is ObservableCollection in my ViewModel.

Thanks in advance,
Kris

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 Jun 2015, 08:06 AM
Hello Kris,

RadDataPager itself does not hold a sorted collection. You can access the same from RadGridView.Items. You can also find the current sort descriptors applied through 
RadGridView.SortDescriptors collection.

Regards,
Dimitrina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Krzysztof
Top achievements
Rank 1
answered on 10 Jun 2015, 08:58 AM

Thanks Dimitrina for your reply.

 

In RadGridView.Items I can find items only in actual page, not all items.

I tried to use RadGridView.SortDescriptors and CollectionViewSource to sort base collection. Unfortunately sorting by RadGridView gives me diffrent collection for this same values. For example:

Name: John, Age: 17

Name: Piter, Age: 16

Name: Rita, Age: 15

Name: Jenny, Age: 16

When I sort on "Age"

RadGridView return: Rita, Jenny, Piter, John

CollectionViewSource with RadGridView.SortDescriptors return: Rita, Piter, Jenny, John

If "RadDataPager itself does not hold a sorted collection", how RadDataPager knew which items gives to RadGridView on actual page? RadDataPager sort base collection on every time when I change page?

Thanks in advance,
Kris

0
Dimitrina
Telerik team
answered on 11 Jun 2015, 10:23 AM
Hi Kris,

I will try to explain the way RadDataPager works in some further details.  Every time you navigate to a page, it internally builds a LINQ query appending Skip and Take clauses and then this query is to be executed on the server. When binding the pager to a LINQ-enabled data source (i.e. IQueryable), the paging will happen on the server out-of-the-box. In case the pager is bound to an IQueryable, it will automatically append Skip(n) and Take(m) statements to this query.

Similarly, sorting in RadGridView is a data operation and we internally generate and execute a LINQ query appending a OrderBy clause to the source collection. 

For example, when sorting on the Description property of the bound item, the generated query would be:
var result = GridViewSourceCollection.OrderBy(x => x.Description);

Then, when using sorting and paging, there is a proper LINQ query built, the method 'OrderBy' must be called before the method 'Skip'.

Regards,
Dimitrina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Sheena
Top achievements
Rank 1
answered on 24 Jul 2015, 04:28 PM

I have a similar situation for this issue and I am able to get the Sort Direction (Ascending or Descending) of the Column but not able to get the Column Name that is being Sorted (Customer Name or Account Number).  How are you able to get this information?  I can see the Column Name while in Debug Mode but not able to retrieve it.

Thanks!

0
Dimitrina
Telerik team
answered on 27 Jul 2015, 11:42 AM
Hello,

You can access it like so:
ColumnSortDescriptor sorting = this.clubsGrid.SortDescriptors.FirstOrDefault() as ColumnSortDescriptor;
if (sorting != null)
{
    var column = sorting.Column as GridViewDataColumn;
    string name = column.Header.ToString();
}

I hope this helps.

Regards,
Dimitrina
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
DataPager
Asked by
Krzysztof
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Krzysztof
Top achievements
Rank 1
Sheena
Top achievements
Rank 1
Share this question
or