✅ Client needs filtering logic - what's the best way to implement?
I have two classes like so:
After my program runs, the List<VirtualProduct> Products variable is filled with objects and a JSON of it is returned to the client.
I want my client who knows nothing about coding to be able to filter products by writing in some language or query what objects he wants to keep in that list, based on certain conditions, like:
"CONTAINS toy", "EQUALS Best Toy In America", "NOT {{StoreName}}"
Should I implement this logic on my own, or use some sort of existing query language that C# can interpret / solution for this?
Thanks!
24 Replies
Think I might do something like this, anyone have any better advice?
I dont get the context. So in the front end, the user already has the entire list of VirtualProducts, and you want to filter them based on certain criterias that the user inputs?
I could interpret this two ways
A) you want to re-invent SQL (I.E. you want SQL)
B) you want to build a GUI
Neither. I want to dynamically filter the IEnumerable<VirtualProduct> or IEnumerable<VirtualStore> in a way that anyone who doesn't understand coding can write. They can create certain filters based on criteria. Like this VirtualProduct MUST contain "test" in the Description @ReactiveVeina @IceGPT
yes, and you said you want this to be a "language"
that already exists, that's SQL
"some language or query"
it can be anything really, just as simple as possible
SQL is as simple as it gets for this kinda thing
any simpler (from the user's perspective), and it becomes drastically MORE complex to implement
eventually i will turn it into a GUI, so i'm unsure as to whether SQL is the best choice
if this is a stopgap, then I think SQL queries are your best bet
sanitized, of course
its a solution for my company only
it's a reasonable compromise between ease of implementation, and burden on the user
yeah, the user is gonna have to learn a little bit
what about this? @ReactiveVeina vs SQL
seems easier to follow no?
p.Description.includes('toy')
but how do you GET to that?
with Jint?
what do you mean?
how so you get the value of "toy" out of the user's input, and determine that the user's intent is to apply it to the "Description" column?
if the user's input is freeform text that you have to parse?
yes it is
eventually, when i have that GUI
i would do something like $"p.{Type}.includes('{SearchTerm}')
Something like that
right
the GUI wpuld be what parses it
or, rather, makes the user pre-parse it for you
yeap
in a sense
i think i would rather take the JS approach instead of SQL
because
if i ever need to do some complex custom filtering logic
it would be easier to implement in JS
More data going over the wire that’s unnecessary
only issue is now when i execute this query (filterQuery): with this: i get this error:
what do you mean?
I think he's assuming you're doing the filtering in JS, instead of sending the criteria down to the API
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.