It seems that moving sorting to the forefront is the best way to achieve the desired result. I will not go into infinite scrolling / pagination, because there are probably better resources out there, but basically track the last line (or page) received and sent along with your request. Hope this helps other issues preventing you from realizing this.
In addition: depending on how real-time data you should probably look for other methods to get it, such as a long poll or WebSockets instead of redialing every X minutes.
Response format
{ 'status' : 'OK', 'last_row_retrieved': 20, 'events' : [{ 'html' : "<div>The regular response</div>", 'sort_attr_1' : 10, ... }] }
Front end
//Maintain a container for the results you get each call. var myevents = []; $.post(...,function(response) { var data = $.parseJSON(response); var events = data.events; for(var i=0;i<events.length;i++) { //Save each event myevents.push(events[i]); } DisplayEvents(); }); //When user tries to sort do so with custom sorting function myevents.sort(function(a,b) { return a.sort_attr_1 - b.sort_attr_2;}); DisplayEvents(); function DisplayEvents() { //loop through myevents and display them however you're doing it }
source share