1

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.

Regis May
  • 3,070
  • 2
  • 30
  • 51

1 Answers1

0

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.

Alexander Mashin
  • 3,892
  • 1
  • 9
  • 15
  • Thank you very much for this solution. This is interesting, as this is very useful to me. However, it will not solve the problem in this case: I need the color to depend on the value of the field. If that requirement would not exist, I could just wrap the output in spans as the SWM documentation suggests. Though this does not solve my problem, I really appreciate you responding to my question as your answer taught me something very useful. Thank you! – Regis May May 04 '21 at 14:34
  • You can do it, but it requires Semantic Result format and Array extensions. If you are familiar enough with those I can elaborate. – IRA1777 May 07 '21 at 17:35