Using OnRead to get remote data but sort locally

1 Answer 19 Views
Grid
Wayne Hiller
Top achievements
Rank 1
Veteran
Iron
Wayne Hiller asked on 19 May 2021, 04:23 PM
I am using OnRead to get remote data but sometimes I want to sort locally (all the data is loaded). Is there a way to do that?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 20 May 2021, 11:54 AM

Hello Wayne,

You do not need to use OnRead for this. You can just fetch all the data from your endpoint and pass it to the grid Data. Then, the grid will take care of all operations such as sorting and filtering (event including grouping) for you without you writing a single line of code.

Nevertheless, if you do want to use OnRead for some reason (which would be the need to customize some behavior), you can easily use the .ToDataSourceResult() extension method we offer: https://docs.telerik.com/blazor-ui/components/grid/manual-operations#telerik-todatasourceresultrequest.

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Wayne Hiller
Top achievements
Rank 1
Veteran
Iron
commented on 20 May 2021, 01:26 PM

The reason I am using the OnRead is this is a generic listing component where most of the time not all of the data is loaded from the server. I just happened to have one or two cases where all the data is read. I decided to just do the sorting on the server side.
Marin Bratanov
Telerik team
commented on 20 May 2021, 01:44 PM

I think that you can still handle the OnRead event and if you have the local data - use .ToDataSourceResult() in the local app, and if not - send it to the server for processing. You could encapsulate all that logic in a service that always returns the same to the grid (see the serialization sample) and do the rest of the logic in the service.
Tags
Grid
Asked by
Wayne Hiller
Top achievements
Rank 1
Veteran
Iron
Answers by
Marin Bratanov
Telerik team
Share this question
or