-1

I came across a problem when I added some multiple value fields to my view (integer and text fields). I tried it on a fresh install to be sure that non of my other modules is causing the problem. An example of the setup of my view:

I have a own content type called "product" which has some fields (product attributes):

Field A (text field - 1 value allowed) Field B (text field - 1 value allowed) Field C (text field - unlimited values allowed) Field D (integer - unlimited values allowed) Field E (integer - unlimited values allowed) Field F (integer - unlimited values allowed) ...

Now, I created a page view that lists all my products in form of a table and where only Field A and Field B are shown (by clicking on Field A all other details of the product is shown).

I want users to be able to "search" the product list depending on their needs. Therefore, I use the exposed sort and filter from the module Better Exposed Filter (BEF). For instance, the integer fields can be filtered by the jquery slider from BEF.

The problem is, that the view displays some products multiple times on the table. I found out that this is due to the multiple value fields. For example, if a product has 4 values in Field D, the product is listed four times. Plus, if this product has 3 values in Field E, the product is listed seven times in the view.

Struggling with this problem, I noticed that there is a setting for multiple value field within the views settings. Altought my multiple value fields are not part of the views display I added them in the views settings and checked "Hide from display". "Display all values in the same row" in the multiple field settings was already enabled. Unfortunaltely, this has no effect. This is strange because the tooltip of the setting is exactely describes my problem.

What can I do to display each product only once in the view regardless if it has multiple values for some fields? Plus, filter and sorts should work for field with mulitple values.

Does someone has experience with this?

Thanks.

  • Have you tried using the regular Views exposed filters? That is what I am using and I am not able to recreate your issue unless there are multiple values that match the query value and that is fixed with the distinct setting. – sareed Jan 6 '15 at 15:20
  • Yes, I cleared caches. In my fresh install I used regular exposed filters of Views. – ThuleNB Jan 6 '15 at 16:12
  • ...What do you mean with "...unless there are multiple values that match the query value...". Let's say product A is available in size 10, 20, 30 and 40. This currently shows me four rows in the views table. If I adjust my exposed jquery slider from min 20 to max 60, currently product A is shown three times. If min is 40 and max 80, product A is shown once. What I try to achieve is to show product A just once even the slider is set to 0-100. – ThuleNB Jan 6 '15 at 16:22
  • Okay. Do you have the query settings set to distinct? – sareed Jan 6 '15 at 16:23
  • Advanced > OTHER > Query settings in your view – sareed Jan 6 '15 at 16:25
0

Now I remember this issue. We managed to get it working with aggregation (Advanced > OTHER > Use aggregation). However, it took a lot of tinkering to get the right settings and I am not sure if it would work for this case. My suggestion is if you do not have a pager use hook_views_post_execute to modify the results and ensure distinct. Something like

function hook_views_post_execute(&$view) {
  if ($view->name === 'your_view') {
    $results = array();
    $nids = array();
    foreach ($view->result as $result) {
      if (array_search($result->nid, $nids) === FALSE) {
        $nids[] = $result->nid;
        $results[] = $result;
      }
    }
    $view->result = $results;
  }
}

There are also modules like Views Aggregation Plus but they did not work for the case I needed them for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.