Preset Filter on Grid Column

I have a DataGrid and in the designer, I set the FilterValue of one of the columns to a certain value (in my case to "true" since the column is bound to a bool property of the data).

When I start the app and show the page, only those entities are shown where the property is "true" and the little filter icon in the column header is shown in red. So the filter is set and it is working.

Now, I clear the filter in the UI and the grid shows also entities, where the poperty is not "true" and the filter icon is shown normal again. So the filter is not applied any more.

However, when I now use the pager control to browse through the entities shown in the grid, the filter automatically gets reapplied whith the old, initial state.

Is there any way that I can set the filter only once (!) when the page is loaded and that the grid does not persist this filter state when I change it afterwards in the UI?

Setting the filter value from code in Load event of the page does not work since the column collection of the grid is not ready at this point. Any ideas?

There is a demo showing exactly this - filter set only once on first render:

You can either override this method in a page partial class or use the Render event of the DataGrid from the designer.

1 Like