Tabular SMW query results: How to display a single column with custom formatting?

171 Views Asked by At

I have a standard SMW query that outputs a table (format=table). However, I'd like to visualize the cells of a specific column in this table by colorizing them.

The simplest thing I could think of to achieve something like this would be to specify a MW template for a column to use for formatting: The output of the query could be the MW template input, the output of the MW template could then be displayed in the table cell.

However, I can not find such an option in the SMW help. So I'm wondering if this could be achieved in such a solution way described above. But maybe there is some other (easy?) way of achieving such a visualization? Such a requirement shouldn't be uncommon, therefore I assume that there is a quite simple solution I just don't know about. Can you help me in this matter? Thank you!


ONE REMARK as I might not have been clear enough in my lines above: I need the formatting to depend on the value. Let's say the presented text should be red, yellow or green, depending on the value. This is why I was thinking about using an MW template for formatting: Here you would be able to distinguish between values and format the output accordingly.

1

There are 1 best solutions below

2
On

You could use CSS to style table column containing certain properties; even site-wide. The solution exploits the fact that the property name is assigned to the table cells containing it as an HTML class.

SMW query:

{{#ask: [[User:+]] [[User edit count::>100]]
| ?User edit count
| format = table
| class = coloured
}}

The class = coloured allows to limit the following style declaration for the property User edit count to tables marked with this class.

In MediaWiki:Common.css add:

table.coloured td.User-edit-count {
    background-color: pink;
}

A working example: https://traditio.wiki/User:Alex_Mashin/columns.