I have a relatively large dataset of items (a few thousand items) that I want to navigate by applying a number of filters client side in a web application. Applying the filtering logic itself is not an issue, the question is about which method to use for updating the table of matching results to get the best user experience. The methods I’ve come up with are:
- Setting the class of each row to hide or show it (using visibility: collapsed to hide it), and keeping the DOM element in the table.
- Keeping a DOM element for each data item, detaching/attaching it to the table to hide and show it.
- Just keep an abstract object for each data item, creating a DOM object on demand to show it.
Which one is likely to give the best user experience? Any other recommended method besides those I’ve listed already?
If the display area has fixed size (or at least a maximum size), and you must filter on the client-side, I would not create a DOM node for each item, but instead reuse a predefined set of DOM nodes as templates, hiding unnecessary templates depending on the number of results from the filter. This will drastically reduce the DOM nodes in the document which will keep your page rendering responsive and is fairly easy to implement.
Example HTML*:
Example JavaScript*:
* Not tested. Don’t expect copy/paste to work, but that would be cool.