Distinguish different subjects and the replies to the subject by color

I have a table view table like this:
ROWID MessageType
Row 0 Subject1
Row 1 Reply1OfSubject1
Row 2 Reply2OfSubject1
Row 3 Reply3OfSubject1
Row 4 Subject2
Row 5 Reply1OfSubject2
Row 6 Reply2OfSubject2
Row 7 Subject3
Row 8 Subject4

I want to distinguish different subjects and the replies to the subject by color (red and blue). Saying Row 0, 1, 2, 3 in red, Row 4, 5, 6 in blue, Row 7 in red, Row 8 in blue. Is there any way to do this?

I tried applying custom CSS as below, it just distinguishes the rows (odd or even), how to distinguish the table by subject and its reply?

CSS Editor:
.knime-table {
border-collapse: collapse;
font-family: Arial;
font-size: 11pt;
}

/table data/
.knime-table td {
text-align: left;
padding: 7px;
width: 150px;
}

/table row/
.knime-table tr:nth-child(odd) {background-color: #d53510;}
.knime-table tr:nth-child(even) {background-color: #affdac;}

/table header/
.knime-table th {
text-align: center;
padding: 7px;
font-weight: bold;
color: #FFFFFF;
background-color: #4472C4;
}

Appreciate it if someone can provide a solution or a workflow to demo the solution.

EDIT: I just noticed that the subject and responses have different lengths in rows. So my solution does not work. As Ivan says below, you need to first figure out which row belongs to which subject.

Hi,
You can do this using a Math Formula node, a Number To String, and a Color Manager node. In the first use an expression like floor($$ROWINDEX$$ / 4) % 2. This will give alternating 0 and 1 every 4 rows. With the Number to String node you can turn that into a categorical value and then assign colors to it using the Color Manager.
Kind regards,
Alexander

PS: As this topic does not belong into KNIME Development, I have moved it.

3 Likes

Hello @Hawk326040,

seems you first need to add new column with unique ID to each subject and then simply follow it with Color Manager node. Can you distinguish when one subject ends and another starts?

Br,
Ivan

2 Likes

Yes, I can get the unique id of each subject and its associated replies.

Thanks very much, Ipazin and AlexanderFillbrunn.
The problem is if using Clor Manager node, it can’t change the color of the whole row, is there any method or node to change the color like below illustration:
image

Hi @Hawk326040,
I believe with the normal Table View this is not possible. However, you could create your own view using the Generic JavaScript View. You will need to write JavaScript for that, though.
Kind regards,
Alexander

1 Like

Hello @Hawk326040,

maybe there is option with CSS to do conditional formatting? I did google it a bit but haven’t found straightforward solution for it so Generic JavaScript View as proposed by Alex might be a way to go. Also there is an existing ticket (Internal reference: AP-5485) to have to have this possibility and will add +1 for you. Upon news someone will update this topic.

Br,
Ivan

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.