Change grid FilterMode invoke OnRead

2 Answers 33 Views
Grid
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
Claudio asked on 21 Mar 2025, 03:48 PM

Hi, i have a TelerikGrid who manage paging and read data using the OnRead property.

On top of my grid i have a button to open/hide the inline grid filter (binding a property with the FilterMode grid property).

Now the problem is: when i open o close the filter (changing the FilterMode property) the OnRead method is invoked.

 

I don't want to do a server request to read data if not necessary, and simply open or close the filter does not affect the data loaded in the current page of the grid.

how to avoid this?

This is a sample code to reply the issue:

https://blazorrepl.telerik.com/cfOnmPFz42OsM8ki11

Thanks

2 Answers, 1 is accepted

Sort by
0
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
answered on 21 Mar 2025, 04:19 PM
I checked the TelerikGrid code, and it appears that changing the FilterMode property automatically triggers the OnRead event. There isn't a built-in way to prevent this behavior.

However, you can implement a workaround by using CSS to hide or show the filter row instead of modifying the FilterMode property. This way, the grid won't trigger a new data fetch when toggling the filter visibility.

Here’s an example of how you can achieve this:

@if (!IsFilterRowDisplayed)
{
    <style>
        tr.k-filter-row {
            display: none;
        }        
    </style>
}

Here is the link to the complete sample code: https://blazorrepl.telerik.com/mzuxQFPA19lknC0g32

Regards,
Anislav Atanasov
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
commented on 24 Mar 2025, 10:11 AM

Claudio, did my suggestion helpt you?
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
commented on 24 Mar 2025, 12:54 PM

Thanks Anislav, the workaround solve the issue but i have to change the behaviour of all grids used in my application.

I think who call OnRead on FilterMode property change is a bug, it should be called only when the filter is updated.

Can you evaluate to solve the issue avoiding to call OnChange for FilterMode property change on next version of the library?

Thanks

Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
commented on 24 Mar 2025, 01:00 PM

I’m not part of Progress, so I’m unable to assist with the further evaluation of this feature. I assume there was a specific reason for implementing it this way, as changing the FilterMode may trigger other actions as well. Unfortunately, I don’t have the time to investigate this further at the moment.

Regards,
Anislav Atanasov
0
Dimo
Telerik team
answered on 26 Mar 2025, 10:56 AM

Hi Claudio,

The Grid fires OnRead in OnParametersSetAsync(). The behavior is by design. We believe it's safer to make the Grid more reactive, rather than less reactive to runtime changes.

If you wish to avoid the database call without using custom CSS, you can cache the received data from the previous OnRead event. Here is a KB article with a similar example: Cache and reuse data in the Grid OnRead event

Regards,
Dimo
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
Grid
Asked by
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
Answers by
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Dimo
Telerik team
Share this question
or