Patch attached that supports 'sAjaxSource'. This means that a page will be rendered as quickly as possible and fetch the results using AJAX/JSON - I've tested it with caching enabled - which requires a slight workaround (i.e. delete the non-ajax cache cids) - the trick I've used is to limit the original results to a single record (which should enable token replacements from the first line) and then fetch the rest on an Ajax call.
Roughly what is involved in this patch:
- Adds a setting to the datatables style plugin to enabled "ajax_defer"; (possibly needs renaming)
- Provides a views query plugin that reduces the original view results to 1 record;
- Implements hook_views_post_execute(), which deletes the original single view result so that the ajax results will cache too;
Hopefully this is something that could be interesting incorporating into the module?
Comment | File | Size | Author |
---|---|---|---|
#22 | 2047907-22.patch | 23.47 KB | rpayanm |
#18 | datatables-ajaxdatasource-2047907-18.patch | 22.12 KB | joelstein |
#10 | datatables-ajaxdatasource-2047907-v3.patch | 22.13 KB | RobinMofo |
Comments
Comment #1
RobinMofo CreditAttribution: RobinMofo commentedThe next day ...
I did some further testing and everything works correctly on the first page load but subsequent visits take a while to display.
This is only appears to happen when caching is enabled - I'll be looking into it further.
Comment #2
RobinMofo CreditAttribution: RobinMofo commentedAttached is a much better patch which does away with the query plugin.
Instead there is a cache plugin which separates the results for the ajax call, works great and even includes a different key for filters.
I'm very happy, I look forward to hearing feedback.
Comment #3
RobinMofo CreditAttribution: RobinMofo commentedoops forgot patch!
Comment #4
duellj CreditAttribution: duellj commentedThanks for the excellent work, frobinrobin! I've had a little time to look through the patch, but haven't had a chance to apply it to test yet. There is a branch open in the repo to include ajax handling within DataTables (https://drupal.org/node/652800/git-instructions/ajax), would you mind taking a look to see if there's anything useful in that branch for you (it's been awhile since I've had a chance to work on it)?
I should have some time in the next few days to take a look at this fully.
Thanks!
Comment #5
RobinMofo CreditAttribution: RobinMofo commentedThank you Duellj .. I've taken a look at the ajax branch but I don't see anything in yours that I don't have?
I think mine is a bit cleaner/simpler due to the cache plugin and additional option in your style plugin... but they look like they pretty much do the same thing... I've tested mine with Views ajax enabled and it's pretty sweet having views filters working in conjunction with an ajax datasource :)
I couldn't understand your ajax return, I'm presuming that it returns JSON via some internal magic? does the display cache that way? I have to say my output doesn't cache the final JSON, just the query (but the majority of a view operation is the query).
My next step was to get the expandable columns working with JSON, I do really like the format of the jquery file in the ajax brach and have been trying to work out how to integrate it with the DataTables callbacks in Drupal.datatables.dataTable:
However, I'm not really strong with jquery so amending the existing code is a bit difficult for me - I'll have a go at it (Otherwise I'll never get better)
Comment #6
RobinMofo CreditAttribution: RobinMofo commentedUpdated patch attached using aforementioned DataTable jquery callbacks for the table manipulation, specifically for enabling the Expandable rows.
'fnHeaderCallback' and 'fnRowCallback' were implemented in this patch, so the expanding works regardless of datasource.
This seems to work with both ajax and caching enabled.
Comment #7
duellj CreditAttribution: duellj commentedStarting to review this patch. A couple of notes:
I get this error with a basic view with no filters:
Should be:
Capitalize first word and end in period
Capitalize first word and end in period. misspelled datatable
This title and description could use a little work. Maybe something like:
Title: Use AJAX
Description: Render results using AJAX instead of rendering all results initially. Useful when loading tables with lots of results.
Use spaces instead of tabs.
Remove method from class (not needed?)
Should be:
Whitespace issues (trailing whitespace and tabs instead of spaces)
Use spaces instead of tabs
Capitalize first word and end in period
Trailing whitespace.
*Obviously
Capitalize first word and end in period
Comment #8
duellj CreditAttribution: duellj commentedAlso, it looks like the AJAX callback returns all results, and doesn't take advantage of paging. It would be much better if it was able to use true AJAX for rendering results (i.e. only returns first x results, then pages through next results using AJAX). I tested with 10,000 entries and it took 7 seconds to load up.
Overall though this is looking like a very promising patch. I like your approach with using the views cache system to generate the query.
I'll be reviewing the JS next (this was all I could get to today).
Thanks for your work frobinrobin!
Comment #9
RobinMofo CreditAttribution: RobinMofo commentedHi Duellj,
Thanks for the review, I've done the corrections in #7... I also updated my netbeans config to remove all trailing whitespace and use 2 spaces on 'continutation indentation'.
The reason it takes a fair time to load so many results is because it (sadly) doesn't cache the rendered JSON output.. depending on your field displays and if they require a lot to render; then it will add some load if you don't use page caching such as Varnish/Boost.
I've been considering why this occurs and how to fix it (or whether to cache it manually), I'm hoping that I just need to set the rendered JSON output as a variable in the cache class.
Would you like me to include Server Processing as an option? or would you prefer it to automatically add itself based on the current Views' pagination settings?
I'll start it as an option (easier) and will get back to you soon.
Comment #10
RobinMofo CreditAttribution: RobinMofo commentedRight, so for some reason I dealt with output caching first, I guess it bothered me more.. So now, output caching for JSON is working and is much faster, especially useful when you are retrieving all rows... my 1500 records dropped from 9 seconds to 3 seconds on the XHR request :)
There's a new option for 'Server Side Processing', which adds the missing 'bServerSide' datatables param - when you enable this, it uses the same callback path as 'AjaxDataSource' but you cannot cache with this option as it never updates (but with such small requests you shouldn't need to).
I also added a hook_views_view to remove the pager if the datatables one has been selected.
Comment #11
RobinMofo CreditAttribution: RobinMofo commentedI've been implementing this for a client and have (yet another!) updated patch.
The latest patch concentrates on bServerSide functionality and removes the styles' render method, improves the cache plugin so that cache keys are regenerated for the same view, which improves cache generation and enables datatables pagination.
The only outstanding issue is the "DataTables Search box" when bServerSide is enabled, datatables expects the server to do the filtering - which is managed by Views' filters and so its very specific to each View created by the user.
I'll need to take a look at the datatable API and see if there's an easy way to override/integrate with it, otherwise we might need to force the search box to be disabled when bServerSide is enabled?
I'll probably attach the latest patch within the next week or so.
Comment #12
jason.fisher CreditAttribution: jason.fisher commentedAre you still able to release that patch? I may have a good use case.
Comment #13
RobinMofo CreditAttribution: RobinMofo commentedI had to stop working on this approach and go another route.
My latest issue is that there is a huge performance gain when using an actual downloadable file (sAjaxSource) but I've mixed sAjaxSource with bProcessing, which in my patch, both work on a path.
I want to change the patch so that options relate better to functionality - providing the three cases:
The options are a bit confusing and whilst we've tried to make them more explanatory, I think they need to mirror the datatable options.
So, there is a fair bit of work to get this into an ideal patch and I haven't any plans to work on this soon - but I don't think it would take massive amounts of time to sort out. My last thoughts were on the file downloadable part, which adds yet more time.
Otherwise if you can't wait then the patch in #10 should work fine, as long as you don't need the search options.
Comment #14
CarstenHarnisch CreditAttribution: CarstenHarnisch commentedJust looking on your patch I saw that you were at the end dropping the data as a "download" but running the render method ? The is definetly really slow as the template rendering will be get involved. Datatable can pretty easily work just with a JSON output.
As a first starting point I made a couple of modifications to the "ajax function" which creates the output.
So feel free to add this to your patch also !
Comment #15
lklimek CreditAttribution: lklimek commentedThis issue definitely still needs some work (at least an answer to CarstenHarnisch's question) - and the correct status here is "needs work". "Needs review" means that there's a working patch awaiting for testing & committing if working well.
Comment #16
niteshdasari CreditAttribution: niteshdasari commentedHi,
I get the latest ajax enabled datatables from the git using command
git clone --branch ajax http://git.drupal.org/project/datatables.git.
But i want to populate the json in view . how can i do that . please provide some inputs.
Thanks & Regards
Nitesh
Comment #17
niteshdasari CreditAttribution: niteshdasari commentedHi,
Does any one integrated this patch to Datatables.if so could you please give some instructions on how to intrgrate this patch to existing datatables in drupal
Comment #18
joelstein CreditAttribution: joelstein commentedWith the patch in #10, I was seeing lots of this error:
Here's an update patch which fixes that error (just a one line change on line 360 of the patch, if you want to compare them).
Comment #19
joelpittetComment #20
joelpittetIt looks like the JS no-longer applies.
Comment #21
lazzyvn CreditAttribution: lazzyvn as a volunteer commentedIf someone is looking for datatables ajax server side and Deferred rendering for speed use my custom module https://www.drupal.org/node/2845642
it support ajax for big data i tested with 10K lines
Comment #22
rpayanmrerolled
Comment #23
dqdWe should reroll the patch against latest 7.x 2.x dev
@lazzyvn: please let's merge forces and stop posting your sandbox project in every issue of this project. This isn't very helpful. Thanks for understanding.
Comment #24
dqdDue to inactivity for years and because of upcoming EOL of Drupal 7 I set it to Closed to cleanup the issue queue. Thanks for taking the time to report and all the hard work here from so many awesome users here and maintainers on this! Read more about EOL of D7 here: https://www.drupal.org/about/drupal-7/d7eol/partners
If this feature is still missing/required/wanted or somebody has some time and can reroll the patch against latest dev branch (2.x) feel free to reopen it.