views:

299

answers:

2

Hi,

I've created a view in Drupal that retrieves a list of nodes. The display of this view is a page and it works perfectly well. It does even allow me to filter its content by argument.

See the current's view configuration (click to enlarge):

alt text

I want to use AJAX to use the filter (by parameter) functionality without reloading the page. I've enabled the "Use AJAX" option but I am not sure on how to continue. Any ideas on how to do that?

By the way, I'm building my own theme (in case that changes anything).

Thanks in advance


Update: Basically, this view works when I browse through section/parameter1, section/parameter2... but I want to do the same with AJAX, without reloading the page. I hope is clearer now

A: 

It's not clear to me what you mean by "to use the filter (by parameter)." AJAX views update the results when selection criteria changes on a given page. You appear to have no selection criteria that might change, so there's nothing to update with AJAX. Selection criteria that might change includes page (you have paging off) and exposed filters (your filter is not exposed). It does not include arguments (which you have), since those don't change on a single page but rather between pages.

Scott Reynen
Basically, this view works when I browse through section/parameter1, section/parameter2... but I want to do the same with AJAX, without reloading the page. I hope is clearer now.
ozke
Yeah, AJAX doesn't work on arguments. What's the point of having separate URLs if you're going to load it all on one page with AJAX? If you want the URL to stay the same, use exposed filters rather than arguments. AJAX works on exposed filters.
Scott Reynen
A: 

Ok, I found a quick'n'dirty solution. You can build a php file that renders the view and then use ajax.load to print it in a div.

The ajax call:

$('#output_div').load('path/ajax_all_projects.php?type=art');

The ajax file (ajax_all_projects.php):

<?php
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$get_param = $_GET["type"];
$arguments = Array();
if(!empty($get_param)){
    array_push($arguments, $get_param);
}

$view = views_get_view('all_projects');
print $view->execute_display('Block', $arguments);
?>

I think that does the trick. I hope it helps someone else. :)

ozke