Welcome to our blog, a regular dose of fresh news, events and products about drupal development and not only.
Of course they also do a lot of other fun geeky stuff, but the point is that they do contribute to the Drupal community, as this is the idea of a community in the first place - to get knowledge and to give it back in an improved form.
We have started a series of articles provided by our developers and each time there is a chance to share something they have, we post it here as well.
So here it goes, this time it is about Drupal Views and the Ajax functionality they have - hence getting through to know its functionality will definitely help Drupal developers achieve their goals.
This article is provided by Sergiu Nagailic.
One of the files which will be loaded is: /views/js/ajax_view.js
If we drill down this file and analyze it, we will understand some of the Views' ajax functionality. Lets take a case and see how we can reuse Views' Ajax.
Reloading a View with specific arguments via Ajax:
Lets say we have 2 views on the same page, for instance we use Panels and we have a left-side view and a content view. The content view is empty on the first page load, but when user selects something in the left-side view we want to reload dynamically the content view with specific arguments passed to it.
But I kept thinking that declaring a custom callback, processing functions (and where are callback functions there are access functions) and custom ajax calls is a wrong way, because Views module handles all of those by default.
All of the Ajax-enabled views instances are stored in Drupal.views.instances and all of them are of Drupal.views.ajaxView type. We can use these instances to make the drupalish ajax calls which will update the views in the right way.
You can tweak viewData and/or instance.element_settings how you want (for instance to load the view onmouseover event) to achieve the right functionality. And we all can forget about writing custom callbacks and just re-using Views' Ajax functionality.