How to make some columns align left and some column align center in React Table - React
Method 1:
Something like this should do the job
columns: [
{
accessor: "firstName",
Header: () => (
<div
style={{
textAlign:"right"
}}
>S Column 1</div>)
},
If you can help me, please provide a demo on CodeSandbox
Play here
Update after OP comment
but for columns which will be centre aligned , their sub cell data will also be centre aligned
Manipulate cell styles like this
Cell: row => <div style={{ textAlign: "center" }}>{row.value}</div>
Play it here
Method 2:
Use can use the headerClassName
and specify a class name, in that class you can specify the rule text-align:center
So the code will look like
const columns = [{
Header: 'Column 5',
accessor: 'name',
headerClassName: 'your-class-name'
},
{
......
}
]
Method 3:
If you have lot of headers, adding headerClassName in all headers is a pain. In that case you can set the class name in ReactTableDefaults
import ReactTable, {ReactTableDefaults} from 'react-table';
const columnDefaults = {...ReactTableDefaults.column, headerClassName: 'text-left-classname'}
and in the ReactTable, use like this
<ReactTable
...
...
column = { columnDefaults }
/>
Note: if you are using bootstrap you can assign the inbuilt class
text-center
toheaderClassName