Drupal Views combine 2 columns into 1?
Asked Answered
B

3

9

I've got two content types, both have a node title and a document attachment, the doc attachment fields are different names (being from two different content types).

In my view, I'm displaying the node title and the file name in a table. The node titles are great all in one column, but the two content typed attachment fields are displaying in two separate columns, making three columns total when there should only be two. Every row has a single doc title, but one or the other column is always blank now depending on which content type's doc title is displayed.

How can I combine these two fields to display in the same column so it looks seamless? It is not important to know that these docs came from two different content types. These are organized by larger taxonomy terms so it's not feasible to just do two different views.

Blindage answered 4/8, 2009 at 14:41 Comment(1)
Alas, the answer was right in the views help: Column By default, each field is its own column. However, you can place multiple fields in the same column. To do this, pick which field you want to represent the column, then pick another field and set the 'column' value to that field. You can place as many fields as you like in a single column, but only the main field in a column can be click-sorted.Blindage
B
14

Alas, the answer was right in the views help:

Column

By default, each field is its own column. However, you can place multiple fields in the same column. To do this, pick which field you want to represent the column, then pick another field and set the 'column' value to that field. You can place as many fields as you like in a single column, but only the main field in a column can be click-sorted.

Blindage answered 4/8, 2009 at 22:33 Comment(3)
Kirk, can you please explain how exactly can this be accomplished?Vuong
In the table format options of the view you can make a field to be in the same column of another field.Danish
I'm amazed that this still works 10 years later in Drupal 8. And if you want line breaks, just use "<br />" as the separator.Subarctic
I
1

I found this answer and it works for me:

http://drupal.org/node/1120304#comment-5111606

Iridosmine answered 13/10, 2011 at 12:34 Comment(0)
C
0

You can use any field as a token in another field in the default Views module.

So if you want to concat text fields together, say you have field A with value "Hello" and field B with value "World" and you want a concat field with value "Hello World":

1) Edit field A, choose exclude from display, do the same thing with field B 2) Create field C as Global: Text and ensure that it is ordered after field A and field B (you can only use fields as tokens if they are defined before the target field). 3) You can now see the replacement patterns available to you just under the value textarea in field C. It will be something like [field A] [field B]

Now if you want to calculate a number field based on 2 other fields the method is similar to concat, except for field C you would use the Global: Math Expression field: 1) Edit field A, choose exclude from display, do the same thing with field B 2) Create field C as Global: Math Expression and ensure that it is ordered after field A and field B (you can only use fields as tokens if they are defined before the target field). 3) You can now see the replacement patterns available to you just under the value textarea in field C. It will be something like [field A]+[field B]

Congius answered 4/11, 2015 at 7:6 Comment(1)
It is correct solution for merge two fields into one. But if we need sort for created new column, we will we do? Suppose we assign sort for that column. It didn't sort correctly.Emulsifier

© 2022 - 2024 — McMap. All rights reserved.