Q: Filter-result to table > Header not on top, but on left

Hi,
I cannot find out, how to build this kind of table structure.
Normally a table-structure is like this:

| Name | Age | Phone |
| John | 23 | :telephone:1235486 |
| Sarah | 44 | :telephone:6876516 |
| Pam | 51 | :telephone:3786541 |
| Nick | 79 | :telephone:4896165 |

But I want a table like this:

| Name | John | Sarah | Pam | Nick |
| Age | 23 | 44 | 51 | 79 |
| Phone | :telephone:1235486 | :telephone:6876516 | :telephone:3786541 | :telephone:4896165 |

And the table should be build by a filter (filtering for [<currentTiddler>tags[]tag[person]] ) with the fields “Name”, “Age”, “Phone”.
I do not need to see the headers (“Name”, “Age”, “Phone”), only the related cells.
I don’t mind, if html or wikitext.

How can I achieve this?
Thanks in advance!

PS:
I tried it like this:

| <$list filter="[<currentTiddler>tags[]tag[person]]">{{!!name}}&nbsp;</$list> |
| <$list filter="[<currentTiddler>tags[]tag[person]]">{{!!age}}&nbsp;</$list> |
| <$list filter="[<currentTiddler>tags[]tag[person]]">{{!!phone}}&nbsp;</$list> |

but, the look is not good, because some text is longer then other. So the cells are not exactly under eachother.

Give this a try:

<$set name=people filter="[<currentTiddler>tags[]tag[person]]">
<table>
<tr><$list filter="[enlist<people>]"><td>{{!!name}}</td></$list></tr>
<tr><$list filter="[enlist<people>]"><td>{{!!age}}</td></$list></tr>
<tr><$list filter="[enlist<people>]"><td>{{!!phone}}</td></$list></tr>
</table>

Notes:

  • Use HTML table syntax to generate the table output
  • Use $set to get the list of people only once. Then use enlist<people> to use that list.

Here’s another way to generate the table that uses nested $list widgets:

<table>
   <$list filter="name age phone" variable=thisfield>
      <tr>
      <$list filter="[<currentTiddler>tags[]tag[person]]" variable=thisperson>
         <td><$text text={{{ [<thisperson>get<thisfield>] }}}/></td>
      </$list>
      </tr>
   </$list>
</table>

enjoy,
-e

That’s it! Thank you!

I took the first one, because I also have to transclude images and managed to do that with the first one, but not with the second.
I am fine with it- it works fine :slight_smile:

But now I have another problem and cannot find out, why and not how to solve it:

I wrote this table inside <appear> and inside <div style> and because of both the rest of the tiddler is kind of broken.
I tried this:
Removing the <div style="...> & the </div> >>problem remains.
Removing the <$appear> & </$appear> >>problem remains.
Removing all of <div style> & all of <$appear> >>problem is gone.

Like this:

<$appear state="$:/temp/state-benefit" hide="👇">

<div style="background: #55C3C3; margin:-10px -12px -14px -11px; padding:7px 0px 4px 10px;">
<$set name=people filter="[<currentTiddler>tags[]tag[person]]">
<table>
<tr><$list filter="[enlist<people>]"><td>{{!!name}}</td></$list></tr>
<tr><$list filter="[enlist<people>]"><td>{{!!age}}</td></$list></tr>
<tr><$list filter="[enlist<people>]"><td>{{!!phone}}</td></$list></tr>
</table>

</div>

</$appear>

How can I solve it, that they are not anymore fighting against eachother?

You need a </$set> after the </table>

Yesss… :+1: But why do I need to finish the <set> when <div> and/or <$appear> exist around it, but I don’t need, when these two do not exist?

As long as the widgets aren’t “nested” inside other syntax (such as <$appear> or <div>), unmatched widgets are automatically closed when the end of the tiddler is reached. This also happens when the end of a macro or procedure definition is reached.

Thus, you could write:

\define showtable()
<$set name=people filter="[<currentTiddler>tags[]tag[person]]">
<table>
<tr><$list filter="[enlist<people>]"><td>{{!!name}}</td></$list></tr>
<tr><$list filter="[enlist<people>]"><td>{{!!age}}</td></$list></tr>
<tr><$list filter="[enlist<people>]"><td>{{!!phone}}</td></$list></tr>
</table>
\end

<$appear state="$:/temp/state-benefit" hide="👇">

<div style="background: #55C3C3; margin:-10px -12px -14px -11px; padding:7px 0px 4px 10px;">
<<showtable>>
</div>

</$appear>