Hi,
How can i embed a views trough php and have ajax working?
I need to pass an argument by code, so i can't use a simple region block print (as print $left).
I tried:
print $view->execute_display('block-1', array($node->nid));
and
print views_embed_view('myview', 'default', $node->nid);
and
print $view_interests->render();
but i never get a views-processed class, meaning that some Ajax processing is faulting, no?
Any reason why?
thanks
PS: I have a view with ajax pager (by views infinite pager module), but since this views-processed is made by ajax.js at views module, i think the best place to post it is here.
Comments
Comment #1
dawehnerDoes this work?
Btw. where do you execute this code?
Comment #2
carvalhar CreditAttribution: carvalhar commentedHi,
Adding $view->override_path didn't change anything...no "views-processed".
I'm using this code inside an include (called by node.tpl.php)
Any idea why views isn't being processed/ajaxed?
thanks
Comment #3
dawehnerDid you tryed to execute this code in a preproces function?
And then just use the new variable in the template file?
Comment #4
carvalhar CreditAttribution: carvalhar commentedok, executing the code at template.php inside a preprocess function makes the "views-processed" appears and ajax is working. And i didn't need the override_path.
But i also need to call by ajax a views refresh after a user submit a form.
I'm passing the ajax url like this:
views/ajax?js=1&page=0&view_name=MYVIEW&view_display_id=block_1&view_args=MYARG&view_path='.$_GET['q'].'&view_base_path=null&view_dom_id=4&pager_element=0
and my ajax call is this:
$.ajax({
type: 'get',
url: $("#hiddenurl").val(), //i get the url above with correct args by an input hidden field
success: function(data){
$('#mycontainer).html(data.display);
},
dataType: 'json',
data: 'js=1' //Pass a key/value pair
});
This ajax call works fine after the form submit. But the views generated doesn't have the class"views-processed" and the ajax (my pager is ajax) doesn't work anymore.
How can i solve the views-processed issue?
Thanks
Comment #5
dawehnerSure, you have to attach the behaviours again.
Comment #6
carvalhar CreditAttribution: carvalhar commentednow i got a JS error:
Drupal.attachBehaviours is not a function
How should i apply it? I tried this:
$.ajax({
type: 'get',
url: $("#hiddenurl").val(), //i get the url above with correct args by an input hidden field
success: function(data){
$('#mycontainer).html(Drupal.attachBehaviours(data.display));
},
dataType: 'json',
data: 'js=1' //Pass a key/value pair
});
thanks
PS: this JS code is a template JS file setup at theme info
Comment #7
dawehner$('#mycontainer).html(data.display);
Drupal.attachBehaviors($('#mycontainer'));
Comment #8
carvalhar CreditAttribution: carvalhar commentednot sure if this influence in something, but i'm using an available hooks from ajax module as a base for my ajax call.
http://drupal.org/node/463258
Drupal.Ajax.plugins.RemoveLoader = function(hook,args) {
if(hook === 'redirect') {
[...] //my code above
}
}
Comment #9
carvalhar CreditAttribution: carvalhar commentedhey #7 worked...you posted as i was writing #8.
Thanks a lot =)
By the way, do you know a good reference about ajax and drupal JS functions?
It's not so easy to find trough google as with other php functions from drupal api...
thanks again
Comment #10
dawehnerThe best thing is probably to read misc/drupal.js
Comment #11
carvalhar CreditAttribution: carvalhar commentedok, i'll study drupal.js, thanks for your help.
i'm marking this issue as closed.
Comment #12
vlooivlerke CreditAttribution: vlooivlerke commentedWhen I use an Ajax view and click on a search button the view search via ajax, but if I press the search button twice certain form elements break and there css change to "views-processed"
Things that break is compact forms and fieldsets in the exposed form filters
Paging the ajax view will then return the filter form elements to normal.
Comment #13
MustangGB CreditAttribution: MustangGB commented