0

I am using Drupal Views module. I have Student accounts table that can have multiple students in it. Is there a way to create a table like the following?

╔════╦═════════════╦═════════════╦═══════╦═════╗
║ id ║ Title       ║ Student Name║ Gender║ age ║
╠════╬═════════════╬═════════════╬═══════╬═════╣
║ 1  ║ Acount 1    ║ Jack        ║ Male  ║ 50  ║
║    ║             ╠═════════════╬═══════╬═════╣
║    ║             ║ Smith       ║ Male  ║ 33  ║
╠════╬═════════════╬═════════════╬═══════╬═════╣
║ 2  ║ Acount 2    ║ Ellis       ║Female ║ 42  ║
║    ║             ╠═════════════╬═══════╬═════╣
║    ║             ║ Joe         ║ Male  ║ 43  ║
╚════╩═════════════╩═════════════╩═══════╩═════╝

My current table shows the data like this:

╔════╦═════════════╦═════════════╦═══════╦═════╗
║ id ║ Title       ║ Student Name║ Gender║ age ║
╠════╬═════════════╬═════════════╬═══════╬═════╣
║ 1  ║ Acount 1    ║ Jack        ║ Male  ║ 50  ║
║════║═════════════╠═════════════╬═══════╬═════╣
║ 1  ║ Acount 1    ║ Smith       ║ Male  ║ 33  ║
╠════╬═════════════╬═════════════╬═══════╬═════╣
║ 2  ║ Acount 2    ║ Ellis       ║Female ║ 42  ║
║════║═════════════╠═════════════╬═══════╬═════╣
║ 2  ║ Acount 2    ║ Joe         ║ Male  ║ 43  ║
╚════╩═════════════╩═════════════╩═══════╩═════╝

I want to avoid the repeat of of id and title columns. Any idea how to do this?

This is the setting for my view: enter image description here

2
  • Dear @Jdrupal, I know this is possible to alter the view, but I want to tackle this using View's Configurations. Commented Sep 19, 2019 at 8:32
  • I'd probably go with custom JS here. Tables are always a pain.
    – leymannx
    Commented Sep 19, 2019 at 9:10

1 Answer 1

0

The only way I can think of doing this without custom coding is by using the Views Field View where you create two different Views Displays, one with the contextual filter, save them both, then "embed" the contextual one into the other view.

This type of database query can be very performance intense, and caching is recommended. Or avoid it if you can.

In your case you can keep your original accounts view, but remove the student fields. Add another Display (Block) that is showing student name gender and age, and add a contextual filter for the account, save the view. Then in your original views display add the field for the student info.

You may need to adjust how the labels are shown, so you don't have them duplicate/in odd places because of the recursion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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