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

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Does this work?

$view = views_get_view('test');
$view->override_path = 'current_path';
print $view->preview();

Btw. where do you execute this code?

carvalhar’s picture

Hi,

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

dawehner’s picture

Did you tryed to execute this code in a preproces function?
And then just use the new variable in the template file?

carvalhar’s picture

ok, 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

dawehner’s picture

Sure, you have to attach the behaviours again.

Drupal.attachBehaviours(newhtml);
carvalhar’s picture

now 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

dawehner’s picture

$('#mycontainer).html(data.display);
Drupal.attachBehaviors($('#mycontainer'));

carvalhar’s picture

not 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
}
}

carvalhar’s picture

hey #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

dawehner’s picture

Status: Postponed (maintainer needs more info) » Fixed

The best thing is probably to read misc/drupal.js

carvalhar’s picture

Status: Fixed » Closed (fixed)

ok, i'll study drupal.js, thanks for your help.
i'm marking this issue as closed.

vlooivlerke’s picture

Version: 6.x-2.12 » 6.x-3.x-dev
Status: Closed (fixed) » Active

When 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.

MustangGB’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)