Nugget 11: Adding Filtering to a Blazor QuickGrid
The best way to add filtering to a Blazor QuickGrid is by creating an expression tree representing the predicate of a LINQ Lambda Expression Where clause.
In Nugget 9 , a simple Blazor app that supports CRUDE operations was created using scaffolding and Entity Framework. Because the app loads a collection of items from the database and index component containing a QuickGrid component was created to display the collection of items.
The above code represents the Index.razor component, which was modified after it was created. Directives are omitted for simplicity.
The component filters the collection of JobPosts by two model properties: JobPost.ApplicationDeclined, and JobPost.JobType using a checkbox and an input field. The input field is defined in the ColumnOptions for the JobType PropertyColumn and is bound to a component string variable, jobTypeSearch. Because this variable is bound to the input field, the variable is updated whenever the user enters a value in the control.
Note that the grid is mapped to a component property, jobPostsQeuriable, a queryable which is filtered using a predicate expression tree.
Now, if we would like to add more filtering by other model properties, all we need to do is update the return value of the Predicate component property.
Comments
Post a Comment