Infinite scrolling w/ server-side processing and adding new entries to beginning of table

Infinite scrolling w/ server-side processing and adding new entries to beginning of table

hburrowshburrows Posts: 3Questions: 0Answers: 0
edited February 2013 in General
I have a use case in which I want to use DataTable as a "log viewer" for a large number of entries and where new log entries will appear. The number of logs are potentially large so I'm using server-side process with infinite scrolling. I would also like to query the backend on a regular interval for any new log entries that have arrived since the table was initially displayed. The server-side processing/infinite scroll works great. However, when I get new log entries and attempt to load them via fnAddData the table essentially gets reset -- and the documentation is clear this usage is not allow. That said, does anyone have any suggestions on how to combine server-side processing and infinite scroll with the ability to inject new rows at the beginning of the table without messing up the scrolling and table pagination state? I'd like any new rows added to the beginning of the table without changing the current pagination state and the user would only see those new rows if they scrolled back to the beginning of the table.

Replies

  • hburrowshburrows Posts: 3Questions: 0Answers: 0
    Should also mention that I'm using the bDeferRender option.
  • allanallan Posts: 63,281Questions: 1Answers: 10,425 Site admin
    As noted in the fnAddData documentation:

    > if you are using server-side processing (i.e. "bServerSide": true), then to add data, you must add it to the data source, i.e. the server-side, through an Ajax call.

    i.e. fnAddData is effectively useless with server-side processing, since it is a client-side action and your data is at the server. If you want to redraw the table with new data you need to call fnDraw which will make an Ajax request to get the latest data.

    > I'd like any new rows added to the beginning of the table without changing the current pagination state and the user would only see those new rows if they scrolled back to the beginning of the table.

    That's a little tricky I think, since the client-side doesn't know where the new data will appear in the new data set, so it can't set the pagination accordingly. The server would probably need to give it that information and then the table do a pagination recalculation and redraw (i.e. server says, the top row form the page you last viewed is now offset 14 (or whatever) from the start, and the table would need to make that request. A bit messy, but I can't see any better way of doing it with the information being held only at the server.

    Allan
  • hburrowshburrows Posts: 3Questions: 0Answers: 0
    Allan, thanks for the feedback.

    What I actually did, and works very well, is to only attempt to update the table with the newest entries (rows) when it's scrolled to be very top. I update the table with the newest entries by calling fnDraw on a regular basis. The goes back to the server and fetches the data starting from the beginning which yields exactly what I want. When the user is scrolled away from the top I disable the regular call to fnDraw and just let the server-side/infinite scroll/deferred render functionality work as normal. It's only when the user is scrolled to the top that updating with the newest entries really make sense anyway because the user wouldn't see them otherwise. As soon as the user scrolls back to the top I re-enable the updating which calls fnData and the table gets refreshed.

    Nice work on this plugin. I've used it extensively on my most recent project and it works very well.
This discussion has been closed.