Firstly, this is likely to lead to a bad user experience if someone is busy doing something with the table, for example, highlighting text when all of this is suddenly re-displayed. If you must reload all the data, at least only update the changed rows. This can be done using the built-in manipulation of javascript tables or any number of jQuery plugins.
Secondly, if this is possible from a computational point of view, it would be much more efficient in terms of data transfer and user experience if you could calculate which lines changed and only send these lines. Assign a globally unique id for each row in your table so that you can easily update only that row with jQuery. Using this technology, itโs also easy to add a visual cue that a particular line has updated, for example, a slight color change, which is often pleasant (if applicable).
My favorite way to do this (without a comet):
- Polling every 10 seconds on a page that only returns if the data has changed. Checking this out is much more efficient than sending all the data all the time. You only need to save the datetime field containing when the last value changed, and check it for the last time that the browser received (send it with the request).
- If it has changed, use jQuery, the
trigger method sends another ajax request, this time waiting for a list of strings that have changed since that datetime. - Refresh affected rows.
Update
Based on your comments, I will just add a few extra notes.
- For polling, you probably use the jQuery method . get () . You said you were using Django, so I suggest using json, which means, in your opinion, you will return JSON data. Here's a simple tutorial to get you started.
- In the callback function, for success, check if there is new data with a logical return from your Django view, and if so, call a function that forces the new ajax call to retrieve the corresponding data (again, a JSON object).
- Using this JSON object, look at each item you want to update, and use the jquery
text function or one of the jQuery table plugins to update the rows.
This is quite a sip and a lot of adventure if you are new to this, but it is a good, clean way to do it.
source share