I am writing a frontend application that will provide a UI enabling users to make certain filter selections. We are creating a data visualization that will be populated by data objects fitting the user’s filter criteria. For example, user might say:
Show me all data objects that have the emails
[email protected]
,[email protected]
, or[email protected]
, but only if those objects also have tagsA
andB
associated with them.
We could represent this in SQL
:
SELECT * from dataPoints
WHERE userEmail in ("[email protected]", "[email protected]", "[email protected]")
...
I’m wondering how to best codify this in JSON so that a frontend user can save a filter. We want to store "JSON that represents the user’s selections" in a database, retrieve the filter JSON from the database, and apply it to JSON data (i.e. filtering happens in the browser).
I think I can represent query instructions in JSON, something like how it’s done here, but I’m wondering… is this not a solved problem? Are there approaches for codifying user filter selections in JSON and for performing client-side filtering?
And to be clear: I’m less concerned with how to apply filter logic to JSON data, and more about "how to represent a user’s query preferences in a JSON object." Once I decide how to represent the filter, I can translate that into functions that iterate over JSON data.
2
Answers
you can use JSON to send array and inner join on it to filter.
in example i created some data because you did not provided any.
output:
as you see, A@… did not show up , since its not matching
I like alasql for things like this. If we defined the JSON model, and then think about a helper function to create the JSON filter stricture into a string that the library understands, we can get most of the way there without reinventing the wheel.
Taking that JSON model into the JAvascript example.
You probably want to think about the filters getting stored, but first pass could be manual or defined when needed. Definitely check out the alasql community though, as it’s likely to save you a lot of effort.