[英]How to style react-table header on sorting
Is there any way to change the background color selected header in react-table . 有什么方法可以更改react-table中选择的标题的背景颜色。 for example: below image, if I click on ID the id should change the background color to red. 例如:下图,如果我单击ID,ID应该将背景色更改为红色。
I tried all the possibilities to change the background color on selection. 我尝试了所有可能的选择来更改背景颜色。
css 的CSS
.ReactTable .rt-th {
-webkit-box-flex: 1;
-ms-flex: 1 0 0px;
flex: 1 0 0;
white-space: nowrap;
text-overflow: ellipsis;
padding: 7px 5px;
overflow: hidden;
transition: 0.3s ease;
transition-property: width, min-width, padding, opacity;
background: green;
}
渲染组件时如何设置激活状态并检查条件?
I agree with the above about using state to toggle the className. 我同意以上关于使用状态切换className的意见。 Below is the javascript, css and html that I would use in a bare bones example. 以下是我将在裸露的示例中使用的javascript,css和html。 The isActive property is set to false and then toggles the value with the handleClick method. 将isActive属性设置为false,然后使用handleClick方法切换该值。
class Application extends React.Component {
constructor (props) {
super (props);
this.state = { isActive:false }
this.handleClick = this.handleClick.bind(this);
}
handleClick () {
this.state.isActive ? this.setState({ isActive: false }) : this.setState({
isActive: true })
}
render() {
return <div>
<div onClick={this.handleClick} className = { this.state.isActive ? "red" : "green"} > Background Color </div>
</div>;
}}
React.render(<Application />, document.getElementById('app'));
The css is rather straight forward. CSS非常简单。
.red
background-color: red
.green
background-color: green
And html 和HTML
<div id="app"></app>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.