Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 7a22e21

Browse files
author
Shammamah Hossain
committed
Fix column widths for selectable and deletable cells.
1 parent f4bad0a commit 7a22e21

File tree

1 file changed

+31
-11
lines changed
  • src/dash-table/components/ControlledTable

1 file changed

+31
-11
lines changed

src/dash-table/components/ControlledTable/index.tsx

+31-11
Original file line numberDiff line numberDiff line change
@@ -649,31 +649,24 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
649649
`.dash-spreadsheet-inner td.dash-delete-cell`,
650650
`width: 30px; max-width: 30px; min-width: 30px;`
651651
);
652-
this.stylesheet.setRule(
653-
`.dash-spreadsheet-inner th.dash-delete-header`,
654-
`width: 30px; max-width: 30px; min-width: 30px;`
655-
);
656652
}
657653

658654
if (row_selectable) {
659655
this.stylesheet.setRule(
660656
`.dash-spreadsheet-inner td.dash-select-cell`,
661657
`width: 30px; max-width: 30px; min-width: 30px;`
662658
);
663-
this.stylesheet.setRule(
664-
`.dash-spreadsheet-inner th.dash-select-header`,
665-
`width: 30px; max-width: 30px; min-width: 30px;`
666-
);
667659
}
668660

669661
// Adjust the width of the fixed row header
670662
if (fixed_rows) {
671-
Array.from(r1c1.querySelectorAll('tr:first-of-type td.dash-cell, tr:first-of-type th.dash-header')).forEach((td, index) => {
663+
Array.from(r1c1.querySelectorAll('tr:first-of-type td.dash-cell, tr:first-of-type th.dash-header')).forEach(td => {
664+
const classname = td.className.split(' ')[1];
672665
const style = getComputedStyle(td);
673666
const width = style.width;
674667

675668
this.stylesheet.setRule(
676-
`.dash-fixed-row:not(.dash-fixed-column) th:nth-of-type(${index + 1})`,
669+
`.dash-fixed-row:not(.dash-fixed-column) th.${classname}`,
677670
`width: ${width} !important; min-width: ${width} !important; max-width: ${width} !important;`
678671
);
679672
});
@@ -682,11 +675,38 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
682675
// Adjust the width of the fixed row / fixed columns header
683676
if (fixed_columns && fixed_rows) {
684677
Array.from(r1c0.querySelectorAll('tr:first-of-type td.dash-cell, tr:first-of-type th.dash-header')).forEach((td, index) => {
678+
const classname = td.className.split(' ')[1];
679+
const style = getComputedStyle(td);
680+
const width = style.width;
681+
682+
this.stylesheet.setRule(
683+
`.dash-fixed-column.dash-fixed-row th.${classname}`,
684+
`width: ${width} !important; min-width: ${width} !important; max-width: ${width} !important;`
685+
);
686+
});
687+
}
688+
689+
// Adjust widths of row deletable/row selectable headers
690+
const subTable = fixed_rows && !fixed_columns ? r1c1 : r1c0;
691+
692+
if (row_deletable) {
693+
Array.from(subTable.querySelectorAll('tr:first-of-type td.dash-delete-cell')).forEach(td => {
694+
const style = getComputedStyle(td);
695+
const width = style.width;
696+
697+
this.stylesheet.setRule(
698+
'th.dash-delete-header',
699+
`width: ${width} !important; min-width: ${width} !important; max-width: ${width} !important;`
700+
);
701+
});
702+
}
703+
if (row_selectable) {
704+
Array.from(subTable.querySelectorAll('tr:first-of-type td.dash-select-cell')).forEach(td => {
685705
const style = getComputedStyle(td);
686706
const width = style.width;
687707

688708
this.stylesheet.setRule(
689-
`.dash-fixed-column.dash-fixed-row th:nth-of-type(${index + 1})`,
709+
'th.dash-select-header',
690710
`width: ${width} !important; min-width: ${width} !important; max-width: ${width} !important;`
691711
);
692712
});

0 commit comments

Comments
 (0)