Skip to content

Commit 4f57bb1

Browse files
committed
fix(filterRows): Show/hide rows using setStyle and removeStyle
Finding row elements and adding/removing classes on them is slower and unreliable
1 parent a04a5a1 commit 4f57bb1

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/rowmanager.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default class RowManager {
1414
'fireEvent',
1515
'wrapper',
1616
'bodyScrollable',
17-
'bodyRenderer'
17+
'bodyRenderer',
18+
'style'
1819
]);
1920

2021
this.bindEvents();
@@ -176,18 +177,16 @@ export default class RowManager {
176177

177178
hideRows(rowIndices) {
178179
rowIndices = ensureArray(rowIndices);
179-
rowIndices.map(rowIndex => {
180-
const $tr = this.getRow$(rowIndex);
181-
$tr.classList.add('dt-row--hide');
180+
const selector = rowIndices.map(this.selector).join(',');
181+
this.style.setStyle(selector, {
182+
display: 'none'
182183
});
183184
}
184185

185186
showRows(rowIndices) {
186187
rowIndices = ensureArray(rowIndices);
187-
rowIndices.map(rowIndex => {
188-
const $tr = this.getRow$(rowIndex);
189-
$tr.classList.remove('dt-row--hide');
190-
});
188+
const selector = rowIndices.map(this.selector).join(',');
189+
this.style.removeStyle(selector);
191190
}
192191

193192
openSingleNode(rowIndex) {

src/style.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ export default class Style {
6060
return;
6161
}
6262

63+
selector = selector.trim();
64+
if (!selector) return;
65+
6366
this._styleRulesMap = this._styleRulesMap || {};
6467
const prefixedSelector = this._getPrefixedSelector(selector);
6568

6669
if (this._styleRulesMap[prefixedSelector]) {
67-
// find and remove
68-
const index = Array.from(this.stylesheet.cssRules)
69-
.findIndex(rule => rule.selectorText === prefixedSelector);
70-
this.stylesheet.deleteRule(index);
70+
this.removeStyle(selector);
7171

7272
// merge with old styleobject
7373
styleObject = Object.assign({}, this._styleRulesMap[prefixedSelector], styleObject);
@@ -80,6 +80,28 @@ export default class Style {
8080
this.stylesheet.insertRule(ruleString);
8181
}
8282

83+
removeStyle(selector) {
84+
if (selector.includes(',')) {
85+
selector.split(',')
86+
.map(s => s.trim())
87+
.forEach(selector => {
88+
this.removeStyle(selector);
89+
});
90+
return;
91+
}
92+
93+
selector = selector.trim();
94+
if (!selector) return;
95+
96+
// find and remove
97+
const prefixedSelector = this._getPrefixedSelector(selector);
98+
const index = Array.from(this.stylesheet.cssRules)
99+
.findIndex(rule => rule.selectorText === prefixedSelector);
100+
101+
if (index === -1) return;
102+
this.stylesheet.deleteRule(index);
103+
}
104+
83105
_getPrefixedSelector(selector) {
84106
return `.${this.scopeClass} ${selector}`;
85107
}

0 commit comments

Comments
 (0)