question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support striped rows in tables

See original GitHub issue

What problem does this feature solve?

When you have a lot of data in a table, it’s easy to skip between rows while reading across the line, so lots of places colour every other row (or every nth row) to make it clearer. Here are [some examples](https://www.google.com/search?tbm=isch&q=striped table rows).

What does the proposed API look like?

Perhaps a new string property on the Table API to allow every nth row to be striped using the same selectors as the CSS nth-child selectors:

  • stripes=even - use the stripe colour for rows 2, 4, 6, …
  • stripes=odd - use the stripe colour for rows 1, 3, 5, …
  • stripes=4 - use the stripe colour on row 4
  • stripes=4n - use the stripe colour on every fourth row: 4, 8, 12, …
  • stripes=4n 2 - use the stripe colour on every fourth row, starting with the second row: 2, 6, 10, …
  • stripes=-n 2 - use the stripe colour on the first two rows: 1, 2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
Evanlai8commented, Mar 7, 2018

I think the proposed is useful

14reactions
shaahiiincommented, Dec 9, 2019

I found two ways to do this as of now:

One way is to use rowClassName prop of Table:

.table-row-light {
    background-color: #ffffff;
}
.table-row-dark {
    background-color: #fbfbfb;
}
<Table
  rowClassName={(record, index) => index % 2 === 0 ? 'table-row-light' :  'table-row-dark'}
  columns={columns}
  dataSource={dataSource}
  loading={loading}
/>

Second way is to use plain CSS

.table-striped-rows tr:nth-child(2n) td {
    background-color: #fbfbfb;
}
.table-striped-rows thead {
    background-color: #f1f1f1;
}
<Table
  className="table-striped-rows"
  columns={columns}
  dataSource={dataSource}
  loading={loading}
/>

Note that rowClassName works only for rows, so for CSS on table headers we can only use plain CSS like above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create A Zebra Striped Table - W3Schools
To create a zebra-striped table, use the nth-child() selector and add a background-color to all even (or odd) table rows: ...
Read more >
Zebra-striping rows and columns - CSS Wizardry
Striping a table's alternate rows couldn't be simpler. By programatically adding a class of odd or suchlike to every other <tr> you can...
Read more >
Zebra Striping: Does it Really Help? - A List Apart
Zebra striping —also known as candy striping or half-shadow—is the application of faint shading to alternate lines or rows in data tables or...
Read more >
Tables - Bootstrap
Tables · Examples · Table head options · Striped rows · Bordered table · Hoverable rows · Small table · Contextual classes ·...
Read more >
Alter bootstrap's table striped Rows to be every other couple ...
I'd like to modify bootstrap ever so slightly so that my striped rows are as such. Row 1 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found