Refresh view from block module via ajax (no exposed filter)

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
pronce's picture

Hi there.
I'm working on an module which povides a form in a block to edit the filter settings of a view. I'm not using an exposed filter, because the form is updating itself via AHAH - selecting one or more categories in a multi select form populates another multi select box with items - and I don't know, if this would be possible with 'hook_form_alter()'.

Now, I update the filter for taxonomy terms (and later some other filter sets) in my view object. After that I wish to update the view without page reloading. But I can't find any function to call in views API which manages the view refreshing. I found the 'ajax_views.js' file but no code example to use it. Is there a simple way using the build in functionalities of views or would it be simpler to use the result of '$view->preview()' with my own AJAX code (e.g. update the content of a wrapper div)?

Regards,
pronce

Comments

pimousse98's picture

Hi pronce,

I am trying to build a simplified views exposed filters form, where a drop down of fields to filter by would, on select, cause the appropriate form input fields to appear - so, building the form dynamically (I am considering maybe just generating a giant form, hiding the unused fields and showing them when the user selects the parameter in the drop-down). Have you succeeded in building the form that updates itself?
Any input would be greatly appreciated.
Thanks,

Delphine
ps. the AJAX updating of the view would be great too...

could this help?

djschoone's picture

$('yourlisteneritem')
.bind('click', function(){
$.get('/views/ajax/?view_name=&view_display_id=&view_args=', null, imageDetails);
return false;
});
});

var imageDetails = function(response) {
var result = Drupal.parseJson(response);
$('yourdiv').append(result.display);
}

Drupal.parseJson is

xiong's picture

Drupal.parseJson is depreciated (http://drupal.org/node/114774).
By using $.getJSON() instead of $.get() could save some code.
In some cases you may consider Drupal.attachBehaviors() in callback function.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: