Using data export in Drupal 6 with view fields

Whether it is a webshop with a list of products or an event organising site with a list of participants, Drupal is commonly used to provide simple database interfaces - allowing people to manipulate, view, import and export data.

One great way to provide data exports is to use the Views Data Export module. This allows us to create a view with rows of fields which can be exported as CSV and XLS format amongst others.

Things can get a bit tricky when the view you want to export includes fields that are themselves views. For instance if you have a view that displays a list of orders (let's call it the order view), and one of the field in your view displays the list of products in that order by using another view, embeded with the Views Field View module (let's call that other view the product view).

What happens when you export the order view, is that the data from the product view gets exported as the original output of that view, with the HTML stripped. In many cases this is not what you would want. One way to get this to work properly is to create a Data Export display for the product view, such that :

  • You set the style as CSV file ;
  • You untick "Quote Values", as it will be the job of the main view to do that ;
  • You untick "Make first row a list of column headers" ;
  • You change the separator to be something else than a comma. A space will work, or in the example of the product view
    where the fields are "quantitiy" and "product_name", we can use " x " so we get "quantity" x "product_name".

Once you have done that, you can edit the order view to change the display used by the Views Field View field and you're done - you can now do data exports of views that embed views in their fields.