This is a reoccurring theme: either AJAX causes data to be requested from the server and then the data is shown to the user or the page is pre-populated (ie. rendered) with data that has some kind of interaction with Javascript.
Here are couple of possibilities I see how to store and manipulate the (complex) data:
Store the data simply in the DOM and use Javascript to fetch-from-DOM, do something with the data and manipulate the DOM accordingly to show the results. Fetching and storing the data (multiple hidden fields) can be a real mess and multiple selectors can be slow compared to getting the data from Javascript. In the pre-populate scenarios the benefits are that the data is indexable/crawable by search engine spiders and the page works without Javascript enabled (it gracefully degrades).
Use Javascript as a container for holding the data and use DOM only to visualize the data. When some action is triggered, the only things fetched from the DOM is something like the entity's ID so we know to which object we are referring to in Javascript. But how is the pre-populated data pushed to Javascript? If we simply render them to DOM, we are back to fetch-from-DOM scenario. We could render the JSON string to the page's
<script
> tags and then populate the DOM (but this might have problems with caching?). Or we could request the data lazily using AJAX (but this causes unnecessary server load).Use a ready made container, like some jQuery table plugin (jqGrid). But it's not possible always to use such a plugin because great deal of customization is needed or the component is simply an overkill for your scenario.
Also, do you tend to render as much as possible on the server (using RenderPartial) side and return possibly both, the data along with their rendered HTML/Javascript?
I've tried searching for articles about this topic without much of success. Any direction, advice and pointers are welcome.