Reputation: 2398
I have a large chunk of json data that I would like to filter client side in the most efficient way possible using a table. Each header has an input filter where the user can enter a string to filter that specific property. There is also a global input filter where the user can issue a "free text search".
Been thinking about ways to do that and would love to hear your opinion on the matter.
Example for purpose of visualizing the table
+---------------+
| Global filter |
+---------------+
+----------+---------+----------+-----------+
| Column 1 | Colum 2 | Column 3 | Column 4 |
+----------+---------+----------+-----------+
| ... | ... | ... | ... |
+----------+---------+----------+-----------+
Option 1:
Upon clicking on a filter input:
This would be OK. But would still mean some overhead as some searches would be done many times.
Option 2:
This would work even better if all I did was to add upon the filters. But the moment I want to change an already populated filter the logic "breaks".
Option 3:
This would be a mix of 1 and 2. Upon clicking on a filter input:
I've brainstorming on my own and option 3 is the best way I could come up with in terms of simplicity and performance.
Am I on the right path? What do you think?
/Patrik
Upvotes: 0
Views: 601
Reputation: 7674
3rd option is better but it looks like there is a minor problem. Assuming you are using AND based filtering you should rather have steps like this
details = [
{user:"A",location:"kansas"},
{user:"B",location:"kansas"},
{user:"C",location:"phoenix"},
{user:"D",location:"phoenix"}
]
Assume [ ]
is a text box. At first both are empty
[user=""] [location=""]
Now user enter a city
[user=] [location=kansas]
//final cache :[{user:"A",location:"kansas"},{user:"B",location:"kansas"}]
now the user tries to enter username
[user=A] [location=kansas]
Cache used for search :[{user:"A",location:"kansas"},{user:"C",location:"kansas"}]
// final cache after step 3: `[{user:"A",location:"kansas"}]`
Now user wants to enter another city
[user=A] [location=phoenix]
// gives 0 results
cache used for search :[{user:"A",location:"kansas"}]
Whenever filtering by some filter say “location” you should not use the result set already reduced by this filter previously.
Upvotes: 1