How to change CSS of columns - ReactTable How to change CSS of columns - ReactTable reactjs reactjs

How to change CSS of columns - ReactTable


From what I understand, you want to add some border when you hover over a column header. If my understanding is correct, you can use :hover pseudo selector over the header class

.hdrCls:hover {  border: 2px solid rgba(0,0,0,0.6) !important;}

Update :

You can manipulate state in onResizedChange handler exposed by react-table

onResizedChange={(newResized, event) => {  let resizedCol = newResized.slice(-1)[0].id;  if(this.state.activeCol !== resizedCol) {    this.setState({      activeCol: resizedCol,      resizing: true    })  }}}

Also, make sure you have to make the resizing state to false on mouseup event. For that I have come up with the below solution.

componentDidUpdate(props, state) {  if (this.state.resizing && !state.resizing) {    document.addEventListener('mouseup', this.onMouseUp);  } else if (!this.state.resizing && state.resizing) {    document.removeEventListener('mouseup', this.onMouseUp);  }}onMouseUp = (evt) => {  this.setState({    activeCol: '',    resizing: false  });  evt.stopPropagation();  evt.preventDefault();}      

For reference:

const ReactTable = window.ReactTable.defaultclass App extends React.Component {  constructor(props) {    super(props)    this.state = {      activeCol: '',      resizing: false    }  }    componentDidUpdate(props, state) {    if (this.state.resizing && !state.resizing) {      document.addEventListener('mouseup', this.onMouseUp);    } else if (!this.state.resizing && state.resizing) {      document.removeEventListener('mouseup', this.onMouseUp);    }  }    onMouseUp = (evt) => {    this.setState({      activeCol: '',      resizing: false    });    evt.stopPropagation();    evt.preventDefault();  }    render() {    const data = [{      name:"Mark",      age:24    },    {      name:"Derek",      age:26    }]    const columns = [{          Header: 'Name',          accessor: 'name', // String-based value accessors!,          headerClassName: 'hdrCls',          className: (this.state.activeCol === 'name') && this.state.resizing ? 'borderCellCls' : 'defaultCellCls'      }, {          Header: 'Age',          accessor: 'age',          headerClassName: 'hdrCls',          className: (this.state.activeCol === 'age') && this.state.resizing ? 'borderCellCls' : 'defaultCellCls'      }];    return <ReactTable      data = { data }      columns = { columns }      showPagination= {false}      onResizedChange={(newResized, event) => {        let resizedCol = newResized.slice(-1)[0].id;        if(this.state.activeCol !== resizedCol) {          this.setState({            activeCol: resizedCol,            resizing: true          })        }      }}    />  }}ReactDOM.render( < App / > , document.getElementById("app"))
.hdrCls:hover {  border: 2px solid rgba(0,0,0,0.6) !important;}.borderCellCls {  border-right: 2px solid rgba(0,0,0,0.6) !important;  border-left: 2px solid rgba(0,0,0,0.6) !important;}.defaultCellCls {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.7.6/react-table.js"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.7.6/react-table.css"></link><div id="app"></div>