Export CSV exports ALL data even if I have a exposed filter search active
yurtboy - September 12, 2007 - 19:31
| Project: | Views Bonus Pack |
| Version: | 5.x-1.x-dev |
| Component: | Views Export |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | duplicate |
Description
is this how it is suppose to be? Or am I suppose to add php to the argument area to make the CSV file be the results of the query the person has done?
Thanks

#1
I'd like to know how to make the export work with the exposed filters i've just set. I think it's probably just down to the CSV icon url?
#2
Here's the fix, it's an additional 1 line that needs to be added to the function
views_bonus_export_views_file_argument()Weirdly, the existing function had a variable defined for just the missing filter arguments, so my fix is to populate that missing variable.
$url_filter = str_replace(base_path() . views_get_url($view, array()) . '?', '', $_SERVER[REQUEST_URI]);I'm not 100% sure if $_SERVER[REQUEST_URI] works on IIS too? I couldn't see any other way of getting the exposed filters arguments in a usable way for building the URL easily.
The function in full for copy n paste testers:
/**
* argument hook that will display the file or display export icons.
*/
function views_bonus_export_views_file_argument($op, &$view, $arg) {
if ($op == 'argument' && ($arg == 'csv' || $arg == 'doc')) {
$view->page_type = 'views_'. $arg;
}
else if ($op == 'post_view' && $view->build_type != 'block') {
$args = views_post_view_make_args($view, $arg, $arg);
$url = views_get_url($view, $args);
$url_filter = str_replace(base_path() . views_get_url($view, array()) . '?', '', $_SERVER[REQUEST_URI]);
$title = views_get_title($view, 'page', $args);
$links = array();
if ($arg == 'csv') {
if (($image = theme('image', drupal_get_path('module', 'views_bonus_export').'/csv.png', t('CSV export'), t('Export @title to an Spreadsheet-readable CSV file', array('@title' => $title)))) && (user_access('export views as CSV'))) {
$links[] = l($image, $url, array('class' => 'xml-icon'), $url_filter, NULL, FALSE, TRUE);
}
}
else if ($arg == 'doc') {
if (($image = theme('image', drupal_get_path('module', 'views_bonus_export').'/doc.png', t('DOC export'), t('Export @title to an Wordprocessor-readable DOC file', array('@title' => $title)))) && (user_access('export views as DOC'))) {
$links[] = l($image, $url, array('class' => 'xml-icon'), $url_filter, NULL, FALSE, TRUE);
}
}
return implode(' ', $links);
}
}
#3
A small update, when no exposed filters have been clicked on (first page load) the CSV output breaks. Small change in the 1 liner to this:-
$url_filter = str_replace(base_path() . views_get_url($view, array()), '', $_SERVER[REQUEST_URI]);Small side effect is two ?? in the url as Drupal l() function adds one too.
#4
You mind posting a patch?
#5
Another small enhancement to this patch...
I used the line that budda suggested adding above, and cleaned it up a bit more, and identified one more (minor) bug regarding this patch that someone else can fix.
Patch is attached. Here is a brief explanation of what still needs fixing.
The idea is that if you are viewing
www.yoursite.com/yourview?exposed_filter_param1=foo
we want to get a link to a CSV like this:
www.yoursite.com/yourview_url/csv?exposed_filter_param1=foo
"$url_filter" will be everything after the question mark, and is basically just the query string.
In this context, it works fine.
But the trouble is, the same view, when you are editing it and setting it up, the view is also visible via
www.yoursite.com/admin/build/views/yourview_name?exposed_filter_param1=foo
The patch as it is gets a bit confused in that context, and the CSV button doesn't work. It shouldn't be hard to fix, but I am going to pass the torch to someone else, as I have no more time to spend on this. :-\
(I too needed to have a view with exposed filters, and wanted to be able to get a CSV export of the user-custom-filtered data, not just the filters as they were set up by the admin. So thanks for starting this patch, budda!)
#6
Patch works for me in normal page view and respect the exposed filters.
#7
#8
I couldn't reproduce the issue in comment #5.
This patch takes the exposed filter data from the view object instead of the url.
#9
I've tested the patch in #8 with both the CSV and the DOC exports. It works well for me, and I've implemented it on our site.
#10
Committed.
#11
Automatically closed -- issue fixed for two weeks with no activity.
#12
It seems that the latest patch added, doesn't work on my installation; no exposed filter data available when submitting the csv-icon for export.
Patch, suggested in http://drupal.org/node/175116#comment-637341 works! (#5 above)
More information: http://drupal.org/node/264529
Someone else with the same problem?
TIA,
Fossie
#13
fix at http://drupal.org/node/265815
marking this one as duplicate since the other issue has the patch already attached.