I did what you are trying to do, and here is my experience. I am using Oracle Site Studio middleware at work. I was looking for a structure that would work with it, but could not find it. So I tried both options below.
1) The database query returns a certain number of rows. I tried 2000 as a test. A simple foreach loop converts the returned data into JSON data. Thus, it literally creates a long array of JSON variables as it moves along the lines. Thus, you imitate the snapshot of the local dababase. JS can access array elements very quickly, and this may surprise you with how quickly you can sort, modify, and delete information.
<script> var appData = [{'id':'0','first':'Sam','last':'Smith'},{'id':'1','first':'Dan','last':'Smith'}]; </script>
JSON data is contained in the script tag. Then jQuery on doc.ready reads the data and, if necessary, adds it to the html text. When the user changes the value of the JSON data, ajax fires and saves the changes to the database. It is not difficult to add such a system to your application. I later used Google Angular.js to bind data to the user interface in order to have a clean MV template, as well as easily perform quick sorting and filtering on the client side. As already mentioned, Backbone.js and other JS structures can synchronize client data with the server.
2) The second way I saved the data on the html page is to scroll the returned lines again using foreach. Then I saved the data in HTML using the old fashioned
<input type="hidden" name="someName" value="someValue" />
Then I used jQuery to process the data and add it to the user interface. If you really want to deal with JSON, you can insert it into HTML variables this way
<input type="hidden name="row1" value="{'color':'red','style':'fancy','age':'44'}" />
Then you can use jQuery or Angular.js to process the data and bind it to the user interface.
Interestingly, many application frameworks do not have a built-in client-side caching system. It is really inefficient to sort the server side selection menu and then rebuild the html. Better sort it in JS and dynamically rebuild the selection menu. There is a security issue here, and you do not want to print personal information in JSON or HTML variables, as it is visible in the view source. You can also embed data on pages using more complex methods. Consider below:
<span class="data" value="1234"></span> $(function () { $('.data').each( function() { var val = $(this).attr('value'); console.log(val);
Then you can use jQuery on doc.ready to process classes called data. You can also enter JSON data into a value and parse it later. Keep in mind that jQuery people are against developers using classes in this way. In my experience, if you donβt go overboard, it works great.