-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QueryBuilder #14
Comments
Hello ;) Thanks for you question! I'm really happy when someone is interested in this library and may using it. I'm using the Query Builder in a wasm application, but it will also work on server side.
<MQueryBuilder T="object" @bind-RuleGroup="mModel.RuleGroup" @bind-RuleGroup:after="OnRulesChanged">
<MQueryBuilderField RuleName="FirstName" Title="@L[nameof(Loc.FirstName)]" PropertyType="typeof(string)" />
<MQueryBuilderField RuleName="LastName" Title="@L[nameof(Loc.LastName)]" PropertyType="typeof(string)" />
<MQueryBuilderComplexField T="Guid" RuleName="EventEmployed" Title="@L[Loc.RuleEventEmployed]" AllowedOperators="new MQueryBuilderConditionOperator[0]">
<FormTemplate>
<MSelect T="Event" Property="@nameof(Event.Name)" Options="mEvents" Value="mEvents.FirstOrDefault(e => e.Id == context.Value)" ValueChanged="async v => { await context.ValueChanged.InvokeAsync(v.Id); }" ValueExpression="@(RenderHelper.GetFakePropertyInfoExpression<Event>(string.Empty, "Id"))" />
</FormTemplate>
</MQueryBuilderComplexField>
</MQueryBuilder> In In the controller I do something like this: var people = mEfContext.Set<Person>().Where(p => p.OwnerId != null);
var query = MQueryBuilderHelper.ApplyRules(people, pRuleGroup, (c) =>
{
return c switch
{
"FirstName" => (u, v) => u.FirstName.ToLower(),
"LastName" => (u, v) => u.LastName.ToLower(),
"EventEmployed" => (p, v) => efContext.Set<Employment>().Any(a => a.PersonId == p.Id && (object)a.EventId == v)
};
});
var result = query.ToArray(); So we prepare a IQueryable (in this case my database table), the user configured MQueryBuilderRuleGroup and a callback, which will map RuleName to an part of a query. There is a small trick implemented:
Fell free to ask any questions. I'd be happy to help you ;) |
also see: |
Thank you for the sample you added. I recently used this Grid component https://demos.blazorbootstrap.com/grid#server-side-filtering-paging-sorting and I find interesting the way the filters are exposed and how you can use them to build your query. In this case, the filters are under each table column header but I would love to be able to build my filters outside the grid with a component like the one you are providing. I use EF Core and https://github.com/alirezanet/Gridify to dynamicly query SQL. |
Oh yes I also had to solve this issue. I want to use server side filtering for my projects, too. I've implemented an Odata adapter and my Simple.Odata.Client fork Oh nice I did now know that something like Gridify exists. I'll keep an eye on it ;) I'd be happy if you can give me some feedback ;) |
Do you plan to make a new release of the library with this component included? |
I've released a new version right now ;) |
What is exactly your purpose with the
MQueryBuilder
?The sample does not go beyond declaring the fields you want to be able to filter on.
How do you declare an instance of the field in the page and then, how are you able in the code to retrieve the actual selected filters with their field, operator and value?
Thank you for your answer.
The text was updated successfully, but these errors were encountered: