RadGrid Sort with Custom Paging

1 Answer 350 Views
Grid
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 29 Jul 2021, 03:56 PM

I am having trouble understanding and finding a good example of sorting a RadGrid with DataTable datasource with custom paging.

It seems to only sort the 1st page.  I have looked but have not found a good example or explaination on how to do this so it sorts the whole grid not just the page you are on.

 

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 03 Aug 2021, 11:34 AM

Hello Roger,

Wen the custom paging is enabled, the Sorting happens on the current page because the Grid only has as many records bound to it. 

To make it sort through all data, you will need to disable the custom paging during sorting.

Our online demo does that, see Custom Paging.

In the NeedDataSource event this is being disabled/enabled based on the other functionalities.

RadGrid1.AllowCustomPaging = !ShouldApplySortFilterOrGroup();

 

This is the Function that checks if there is Filtering, Sorting or Grouping applied. Returns true if any of that checks out:

public bool ShouldApplySortFilterOrGroup()
{
    return RadGrid1.MasterTableView.FilterExpression != "" ||
        (RadGrid1.MasterTableView.GroupByExpressions.Count > 0 || isGrouping) ||
        RadGrid1.MasterTableView.SortExpressions.Count > 0;
}

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 03 Aug 2021, 01:25 PM

Attila,

 

I did add the above code to my grid and the sorting did not change.  It still only sorted the 1st page.  I also have AllowPaing = true.  I set this to false too, but nothing changed.  Same problem.

Attila Antal
Telerik team
commented on 03 Aug 2021, 02:26 PM

We do not have examples as filtering on different sets of data in .NET is common knowledge. But I can suggest you look into the Dynamic Linq topic. For example here is a StackOverflow article that can help you: How I can filter a dataTable with Linq to datatable?

 

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 03 Aug 2021, 02:30 PM

I am not interested in filtering, just sorting a radgrid with pages when I have a datasource from a sql call.   Filtering is not my issue.  It is the sorting with multiple pages.  

In the example provided by you guys you use an Object class as your data source and do a select again on that object with rowsize.  My original call to this datasource if of all the rows, hence I have many pages.  The paging works as expected, just not the sort.

 

Attila Antal
Telerik team
commented on 04 Aug 2021, 07:29 AM

It does not matter for the Grid if you bind DataTable, an Object, an Array, or a List. Custom paging requires you to enable two properties "AllowPaging" and "AllowCustomPaging" and in the NeedDataSource event, you need to implement a code that will fetch the number of rows set in the Grid's PageSize (default 10) starting from the row index relative to the Current Page Index. That is it for the Custom Paging.

However, if you sort the Grid, only the current page will be sorted. Therefore, when you need to write a logic that will check if the Grid has been sort, and disable the Paging. See my answer and also check out the source code of the Online Demo.

Tags
Grid
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Attila Antal
Telerik team
Share this question
or