I have a table where the first column stretches over two rows. The following columns have two separate rows.
The table needs to consist of many of these "doubled rows". So far, no problem.
The style should be a zebra-pattern, which I achieve with this code (note, the CSS is in react/glamorous format):
const StripedTable = glamorous(Table)({
'& th, & td': {
padding: '4px',
},
'& tfoot tr': {
background: '#DDDDDD',
},
'@media screen': {
['& > tbody:nth-of-type(even), ' +
'& > tbody:only-of-type > tr:nth-of-type(even)']: {
backgroundColor: '#EEEEEE',
},
['& > tbody:not(:only-of-type):hover, ' +
'& > tbody:only-of-type > tr:hover']: {
background: '#DDDDDD',
},
},
},
({doubleRow}) => {
if (doubleRow) {
return {
'@media screen': {
// overwrite standard striped coloring that is used for "normal" table rows
['& > tbody:nth-of-type(even), ' +
'& > tbody:only-of-type > tr:nth-of-type(even)']: {
background: '#FFFFFF',
},
// Think in groups of 4 and color every two rows identical
['& > tbody:nth-of-type(even), ' +
'& > tbody:only-of-type > tr:nth-of-type(4n), ' +
'& > tbody:only-of-type > tr:nth-of-type(4n-1)']: {
background: '#EEEEEE',
},
['& > tbody:not(:only-of-type):hover, ' +
'& > tbody:only-of-type > tr:hover,' +
'& > tbody:only-of-type > tr:hover + tr']: {
background: '#DDDDDD',
},
// FIXME hovering groups don't fit when mouse over even rows
['& > tbody:only-of-type > tr:nth-of-type(even):hover,' +
// the following does not work of course, but it should show
// what is intended. "- tr" can't work, as html works from top to
// bottom only
'& > tbody:only-of-type > tr:nth-of-type(even):hover - tr']: {
background: '#DDDDDD',
},
},
};
}
}
);
So, the comments should clarify my problem a bit more. How do I select, say, the second row which I hover together with the first row, i.e. the PREVIOUS one? Putting a tbody around every two rows and selecting that is not an option.
EDIT: Here is the html structure of one of the rows in JSX. Note that the DOMs are styled differently and got their own component, but their function is identical to tr and td:
<TableRow>
<TableData rowSpan="2">
{'Title of Row'}
</TableData>
<TableData>
{data1}
</TableData>
<TableData>
{data2}
</TableData>
<TableData>
{data3}
</TableData>
<TableData>
{data4}
</TableData>
</TableRow>
<TableRow>
<TableData colSpan="4">
{veryLongText}
</TableData>
</TableRow>