Set class for css styles on a cell or row based on data
See original GitHub issueI would like to be able to do something like this.
const data = [
{ x: 1, y: 2},
{ x: 2, y: 3}
];
const getClass = (cell, row) {
if (row.x == 1) {
return "bg-info";
} else {
return "bg-warning";
}
}
const MyTable = () => (
<BootstrapTable data={data} keyField="x">
<TableHeaderColumn dataField="y" **dataClass={getClass}** />
</BootstrapTable>
);
When rendered, MyTable
would have the bg-info
class on the first row and bg-warning
on the second row. This would result in the background of the cells being colored appropriately.
I tried setting dataFormat={cellFormat}
on the columns, where cellFormat
returns <span bsClass="{style}"> {cell} </span>
with style being the style name, but that did not work. Setting class
instead of bsClass
also did not work.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Use CSS to change the style of each row depending on ...
Use CSS to change the style of each row depending on the content · 1. Display element B if element A is empty...
Read more >Apply css style to a row based on a value of its data
I'm able to style the single cells with an external script that read data from the data-style attribute and append to the <td>...
Read more >Is it possible to select a set of table cells for CSS styling by ...
The only solution was to add a class to every cell in the relevant columns, and select on tr.rowclass td.colclass .
Read more >Adding a css class to row based on condition; GridModel ...
Class will be added based on data from a column in the row. I few things about my grid; I'm using GridModel approach...
Read more >Cell Styles: Styling & Appearance Feature of our Datagrid
Use CSS rules to define Cell Style based on data content, e.g. put a red ... cellClass: 'my-class' } // return same array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hey @AllenFang here’s what I did:
I think the issue is actually that
noShiftDataRowIds
is an array of the index’s for my data and that is not changing because it has no reason to. What I will do is instead of it being an array of index I will make it an array of the primary key instead and that should work. 😃👍 thanks for help
Yep all sorted @AllenFang !