gustavnavar / Grid.Blazor

Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
GNU Lesser General Public License v2.1
696 stars 134 forks source link

Query: Multiple custom filters and "Apply" button - Possible to defer http quest? #267

Open topherZa opened 3 years ago

topherZa commented 3 years ago

Hi,

Using client side blazor and setting filters on a grid, Is it possible to defer the http request until all filters are set on a page and an apply button clicked? I don't use the GridHeaderComponent and so the filters sit outside of the grid. One or many are visible at a time.

If I look at the GridComponent.AddFilter method it looks like each time I add a filter, an http request will be made?

My current scenario is that I have multiple filters on a page, of which, a user could set various values, on some or all of the filters, and once happy with the criteria, click an apply button.

But the only way I can see it working right now is that when clicking apply, each custom filter is signalled that it is to be applied to the grid, and at which point each filter calls _grid.AddFilter(column, filterCollection). I then get a number of api requests hitting my server all with different filter parameters.

Thanks for any feedback in advance!

topherZa commented 3 years ago

I think I have a solution.

I looked at the AddFilter method some more and realised that the _grid.Grid.AddFilterParameter(Column, filters); method was public on the cgrid. So I'll loose the onbeforefilterchanged and after events if I call that myself in each filter, which is ok as I don't currently hook into them. Then I'm thinking I can add references to all my custom filters, add them to a list, loop through the list and call their ApplyFilters which will call _grid.Grid.AddFilterParameter, and then after the loop, call UpdateGrid().

I think this will work.