Mixing HTML initialization with server side refreshes
Mixing HTML initialization with server side refreshes
Hi Allan,
I like that the system is based on progressive enhancement and what I'm trying to do is generate the HTML table on the initial load (so it gets indexed in search results) and then do subsequent refreshes via Ajax. I've got it working that way however it seems a little contrived -- I set bServerSide and fnServerData and then ignore the initial call to the server triggered by the initialization. Is there a better way to do this?
Thanks!
Bruce
I like that the system is based on progressive enhancement and what I'm trying to do is generate the HTML table on the initial load (so it gets indexed in search results) and then do subsequent refreshes via Ajax. I've got it working that way however it seems a little contrived -- I set bServerSide and fnServerData and then ignore the initial call to the server triggered by the initialization. Is there a better way to do this?
Thanks!
Bruce
This discussion has been closed.
Replies
That sounds a little complicated :-). Have you tried simply having a basic HTML table (perhaps with the first 10 results) rendered on page load (i.e. no Javascript) and then initialising DataTables with server-side processing? DataTables will remove the rows for the original table (basically discard them) and draw in the new information brought in by Ajax.
Allan
Yes, I thought of that but I wanted to avoid the extra round-trip and processing for the DataTables initialization server-side load. It seems redundant since the initial HTML layout looks exactly like the results produced by DataTables. I looked through the code a bit and it seems all that would be required would be an initialization flag telling DataTables to just add its formatting and events but not call the fnServerData function. This way DataTables would be initialized, the current HTML would still be displayed, and there wouldn't be the extra data load.
I wouldn't bother doing all the extra work if getting indexed by the search engines wasn't so important. The reason I'm switching to DataTables is because of the in-place progressive enhancement so I can have a fully formatted table for non-javascript users (search engines) while still adding all the cool Ajax/javascript features for normal users.
Awesome job though... really clean implementation.
Best
Bruce
Ah yes I see what you mean. I hadn't considered the XHR at page load, which as you rightly point out in this situation is effectively redundant. There is currently no easy option to avoid this extra XHR I'm afraid. The cleanest method would probably be to put a catch into DataTables which will stop the Ajax load function from doing anything when the draw count is 1 (first draw). This is certainly something I'll think about adding in future - I'm 100% for progressive enhancement!
Regards,
Allan
if ( oSettings.oFeatures.bServerSide && !_fnAjaxUpdate( oSettings ) )
I thought it might be as simple as adding an extra clause to that of && oSettings.iDraw > 0, but I'm uncertain of the consequences of doing that. Looks like if we simply had another case there for the first time, that might let us really have the progressive enhancement and avoid the unnecessary first XHR call.
Am I on the right track? If you were to add an additional setting for this, is that where you'd try to put the check for the setting?
It sounds simple enough to add an extra check to see if this is the first draw. Any thoughts on carteriii's sugestion of modifying _fnDraw?
1. The table doesn't have all of the information needed at load time, so the information element will be wrong
2. For complete progressive enhancement you'll need to provide pagination for users without Javascript so they can access all records.
Allan