so I am using an npm package called react-data-table-component. A problem that I am having with this is that I can’t adjust the width enough to display the full header text, as you can see here:
Here is the custom styling that I am using with this data table:
JavaScript
x
57
57
1
const CustomStyle = {
2
noData: {
3
style: {
4
display: 'flex',
5
alignItems: 'center',
6
justifyContent: 'center',
7
color: 'white',
8
},
9
},
10
rows: {
11
style: {
12
zIndex: 2,
13
minHeight: '30px !important', // override the row height
14
fontSize: '14px',
15
whiteSpace: 'pre',
16
},
17
},
18
table: {
19
style: {
20
zIndex: 1,
21
},
22
},
23
headRow: {
24
style: {
25
minHeight: '40px',
26
borderTopWidth: '1px',
27
borderTopStyle: 'solid',
28
borderBottomWidth: '2px',
29
},
30
},
31
headCells: {
32
style: {
33
fontSize: '16px',
34
justifyContent: 'left',
35
wordWrap: 'breakWord',
36
},
37
},
38
subHeader: {
39
style: {
40
minHeight: '40px',
41
},
42
},
43
pagination: {
44
style: {
45
minHeight: '40px',
46
},
47
pageButtonsStyle: {
48
borderRadius: '50%',
49
height: '40px',
50
width: '40px',
51
padding: '8px',
52
margin: 'px',
53
cursor: 'pointer',
54
},
55
},
56
};
57
Here is the width setting that I am using for each column:
JavaScript
1
44
44
1
const columns = [
2
{
3
name: 'Action',
4
selector: row => row['CASE_ID'],
5
width: '6%',
6
maxWidth: 'auto',
7
cell: row => {
8
return (
9
<div>
10
<Row>
11
<Col className="ml-3">
12
<Link to={{ pathname: "/wlmonitoring/user-case-wl", caseID: row.CASE_ID, cifID: row.NO_CIF }}>
13
<img alt="" src={editIcon} className="edit-icon" />
14
</Link>
15
</Col>
16
</Row>
17
</div>
18
);
19
},
20
},
21
{
22
name: 'Case ID',
23
selector: row => row['CASE_ID'],
24
width: '7%',
25
maxWidth: 'auto',
26
cell: row => {
27
return (
28
"WMC" + row.CASE_ID
29
)
30
}
31
},
32
{
33
name: 'Created Date',
34
selector: row => row['AUDIT_DATE_CREATED'],
35
width: '10%',
36
maxWidth: 'auto',
37
sortable: true,
38
cell: row => {
39
return (
40
moment(row.AUDIT_DATE_CREATED).format(dateFormat)
41
)
42
}
43
},
44
Currently I am using percentage to define the width, but I tried setting the exact width in pixel, but that would cause the last header to protrude out of the table like so:
If anyone can help me figure out what the exact issue is I would really appreciate it.
Advertisement
Answer
Just add this style to your App.css or App.scss and do hard refresh ctrl+shift+R
JavaScript
1
4
1
.lnndaO {
2
white-space: pre-line !important;
3
}
4