Handling large grid datasets in JavaScript

teleball picture teleball · Dec 6, 2010 · Viewed 8.4k times · Source

What are some of the better solutions to handling large datasets (100K) on the client with JavaScript. In particular, if you have multi-column sort and search capabilities, how do you handle fetching (and pre-fetching) the data, client side model binding (for display), and caching the data.

I would imagine a good solution would be doing some thoughtful work in the background. For instance, initially, if the table was displaying N items, it might fetch 2N items, return the data for the user, and then go fetch the next 2N items in the background (even if the user hasn't requested this). As the user made search/sort changes, it would throw out (or maybe even cache the initial base case), and do similar functionality.

Can you share the best solutions you have seen?

Thanks

Answer

DarrellNorton picture DarrellNorton · Dec 6, 2010

Use a jQuery table plugin like DataTables: http://datatables.net/

It supports server-side processing for sorting, filtering, and paging. And it includes pipelining support to prefetch the next x pages of records: http://www.datatables.net/examples/server_side/pipeline.html

Actually the DataTables plugin works 4 different ways: 1. With an HTML table, so you could send down a bunch of HTML and then have all the sorting, filtering, and paging work client-side. 2. With a JavaScript array, so you could send down a 2D array and let it create the table from there. 3. Ajax source - which is not really applicable to you. 4. Server-side, where you send data in JSON format to an empty table and let DataTables take it from there.