1

I have two views that I would like to combine into one.

The first view shows all items of X where company ID = Y. This is to give preferential sort to the client first, and then everyone else.

So I created a second view, all items of X, where company ID != Y.

I created it as an Attachment to attach to the first view, but I don't think I got the intended result.

How can I combine these views so the first view results are listed first, and then the second view is too, using the same pager, filters, and arguments?

Is there any way of achieving this without programming it?

Kevin
  • 13,153
  • 11
  • 60
  • 87
  • Check out this tutorial: http://sethsandler.com/code/drupal-6-creating-activity-stream-views-custom-sql-query-merging-multiple-views-part-1/ – madmatter23 Mar 02 '12 at 06:06

7 Answers7

2

From a MySQL point of view, the order-by-field syntax would be the appropriate way to handle this. Example:

SELECT * FROM tickets ORDER BY FIELD(priority, 'High', 'Normal', 'Low');

It would be great if there is a module that add this kind of functionality to Views, but AFAIK, it does not exist.

If you want to solve this without programming, I think you can use the rules module to automatically set the 'sticky' checkbox on nodes where company ID = Y. With that in place, you can order the View on the sticky value.

marcvangend
  • 5,592
  • 4
  • 22
  • 32
1

Along the lines of the 'sticky' idea, if you didn't want to override that, maybe you could add a checkbox field to the company type -- isClient. Make it false for everyone except the client, and sort by that.

I haven't done this, but maybe you need to create both versions as attachments, and attach them both to another display...?

sprugman
  • 19,351
  • 35
  • 110
  • 163
0

for drupal 5 there was views union. Someone started something for D6, but I don't know how far they got.

http://drupal.org/node/275162

easement
  • 6,119
  • 3
  • 29
  • 36
0

Create the second view as an attachment and attach it to first.
Set all Inherit arguments, Inherit exposed filters and Inherit pager to Yes.

farzan
  • 1,160
  • 2
  • 14
  • 25
  • Thats what I did, but it shows 2 pagers where one view ends and the other begins. – Kevin Apr 06 '10 at 19:08
  • Well, I created a test view like this: - A page display with a filter. - An attachment display with another filter. - I attached the attachment "before" the main display. - I set the Inherit arguments, Inherit exposed filters and Inherit pager to Yes and Render pager to No. It worked _almost_ fine. A pager appeared under the main display that affects the attachment. But there is a big problem that I think it makes you reconsider all the approach: if the attachment display has more "pages" to display than main display, you cannot access them. Pager has only links to main display pages; no more. – farzan Apr 06 '10 at 19:31
0

how is the client parameter passed to the view? as an url argument? if so, you can create your second view like i outline here and then select the exclude the argument option on the appropriate location.

Community
  • 1
  • 1
Peter Carrero
  • 1,596
  • 2
  • 13
  • 13
0

A little bit later... but I've found a better solution using only the Views module:

  1. Create a Block View with that shows the first list that you need ("all items of X where company ID = Y")
  2. Create another View that must be a "Page view" with the second list (all items of X, where company ID != Y)
  3. In the "HEADER" settings of this second view, click "Add" and select "Global: View area".
  4. In the "View to insert" list, select the first you have created (and check "Inherid contextual filters" if you are using it)

And that's it!

0

usually the easiest way to achieve this is with a small hook_query_alter, but that requires a small amount of programming.

messedup
  • 1,098
  • 1
  • 10
  • 12
  • With views, I believe there's a dedicated, specific function for altering the views query. It's new since the last year or so. I tried changing the views query with hook_query_alter before that and it turned out to be quite a mess of code. – James Apr 18 '11 at 02:53
  • That is correct, but sometimes you need to edit the query directly if it is not supported by views. The approach you mention is hook_views_alter but you can find all the information in the advanced_help documentation – messedup Apr 18 '11 at 04:30