Extended GridDataProviderRequest for Server side searching #833
Replies: 3 comments
-
Hello @bluisanajmr, Thanks for providing this proposal for enhancement. We decided not to provide any built-in filtering capabilities, as the way to apply the filtering criteria depends on the architecture of the application (hosting model, data layer, etc.). PS: Be careful, your example is vulnerable to SQL injection attacks. You must avoid assembling SQL commands from user-originated input. In your code, this line... sqlstr += searchstr.PropertyName + " like '%" + searchstr.SearchValue + "%' and "; ...can be exploited by malicious input, such as |
Beta Was this translation helpful? Give feedback.
-
Very true about the sql injection. Our backend code is applying the filters through entity framework not concatenated SQL statements. Our code is very complicated to explain. I just put this together as a very dirty example of this could be used. |
Beta Was this translation helpful? Give feedback.
-
In my view this idea is architecture agnostic and very useful. All this does is build a structure to pass filters to your backend in a uniform way. The developer still has to decide how to apply the filters to their data, which will be different for each architecture as you point out. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have been using the HXGrid with client-side sorting, filtering, and paging for a while now. Recently, I needed to implement all of these functionalities server-side to handle datasets with millions of records. I wanted to share how I extended the GridDataProviderRequest object to accommodate filter terms (referred to as "search" in my code) in case someone else might find this useful or it could be integrated into the HXGrid.
My goal was to create a consistent way to pass filter terms to my API endpoints and then apply these filters to my LINQ to SQL queries without hardcoding for each entity. When my extended GridProviderRequest object is instantiated, it generates a list of PropertyName and SearchValue objects based on the type of entity that the grid is using as its data source. This approach allows me to automatically generate filters in my LINQ queries using a foreach loop in my API, without the need to hardcode column names or other details.
This concept could be expanded to become part of the default GridDataProviderRequest, and optionally used by developers who choose to implement filtering within HXGrids.
To start with I implement filtering much like the online example: https://havit.blazor.eu/components/hxgrid#header-filtering
Inside of my GetGridData (the datasource for my grid) method I implement my extendedGridProviderRequest and add filter variables that are bound to my Grid Header inputs.
Then in my API that gets called to provide the data for the grid I use the Filter(search) terms like this.
This is ExtendedGridDataProviderRequest
Beta Was this translation helpful? Give feedback.
All reactions