Skip to content

Commit a392f73

Browse files
authored
Merge pull request #1968 from nickmelnikov82/fix/style-header-conditional
Fix table incorrect highlight
2 parents e9e42d2 + d5b0aff commit a392f73

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1616

1717
### Fixed
1818

19+
- [#1968](https://github.com/plotly/dash/pull/1968) Fix bug [#1877](https://github.com/plotly/dash/issues/1877), code which uses `merge_duplicate_headers` and `style_header_conditional` to highlight columns, it incorrectly highlights header cells.
20+
1921
- [#2015](https://github.com/plotly/dash/pull/2015) Fix bug [#1854](https://github.com/plotly/dash/issues/1854) in which the combination of row_selectable="single or multi" and filter_action="native" caused the JS error.
2022

2123
- [#1976](https://github.com/plotly/dash/pull/1976) Fix [#1962](https://github.com/plotly/dash/issues/1962) in which DatePickerSingle and DatePickerRange are extremely slow when provided a long list of disabled_days.

components/dash-table/src/dash-table/components/HeaderFactory.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,35 @@ export default class HeaderFactory {
123123

124124
const ops = this.getHeaderOpCells(operations, opStyles, headerOpEdges);
125125

126+
const filteredStyles = this.filterMergedCells(
127+
wrapperStyles,
128+
labelsAndIndices
129+
);
130+
126131
const headers = this.getHeaderCells(
127132
wrappers,
128133
contents,
129-
wrapperStyles,
134+
filteredStyles,
130135
headerEdges
131136
);
132137

133138
return this.getCells(ops, headers);
134139
}
135140

141+
filterMergedCells = memoizeOne((cellsArray, labelsAndIndices) => {
142+
const filteredCells = [];
143+
for (let row = 0; row < cellsArray.length; row++) {
144+
const rowCells = [];
145+
for (let col = 0; col < cellsArray[row].length; col++) {
146+
if (labelsAndIndices[row][1].includes(col)) {
147+
rowCells.push(cellsArray[row][col]);
148+
}
149+
}
150+
filteredCells.push(rowCells);
151+
}
152+
return filteredCells;
153+
});
154+
136155
getCells = memoizeOne(
137156
(opCells: JSX.Element[][], dataCells: JSX.Element[][]) =>
138157
arrayMap2(opCells, dataCells, (o, c) =>

components/dash-table/tests/selenium/test_header.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,42 @@ def test_head005_no_warnings_emitted(test):
142142

143143
wait.until(lambda: target.column(6).get().get_attribute("colspan") == "4", 3)
144144
assert test.get_logs() == []
145+
146+
147+
def test_head006_style_merged_columns(test):
148+
app = get_app(
149+
dict(
150+
columns=[
151+
{"name": ("0"), "id": "x"},
152+
{"name": ("0"), "id": "y"},
153+
{"name": ("1", "1a"), "id": "a"},
154+
{"name": ("1", "1b"), "id": "b"},
155+
{"name": ("2", "2a"), "id": "c"},
156+
{"name": ("2", "2b"), "id": "d"},
157+
],
158+
merge_duplicate_headers=True,
159+
style_header_conditional=[
160+
{
161+
"if": {"column_id": f"{c}"},
162+
"backgroundColor": "green",
163+
"fontWeight": "bold",
164+
}
165+
for c in ["a", "b"]
166+
],
167+
)
168+
)
169+
170+
test.start_server(
171+
app,
172+
debug=True,
173+
use_reloader=False,
174+
use_debugger=True,
175+
dev_tools_hot_reload=False,
176+
)
177+
178+
target = test.table("table")
179+
wait.until(lambda: target.column(0).get_text(0) == "0", 3)
180+
assert "green" in target.column(2).get(0).get_attribute("style")
181+
assert "green" in target.column(2).get(1).get_attribute("style")
182+
assert "green" in target.column(3).get(1).get_attribute("style")
183+
assert test.get_logs() == []

0 commit comments

Comments
 (0)