Skip to content

Commit 3de43c9

Browse files
authored
Merge pull request #210 from sokumon/no-message-ux
fix(ux): better no data experience
2 parents 4879089 + fc94f24 commit 3de43c9

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/body-renderer.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import HyperList from 'hyperlist';
2-
32
export default class BodyRenderer {
43
constructor(instance) {
54
this.instance = instance;
@@ -15,9 +14,10 @@ export default class BodyRenderer {
1514
renderRows(rows) {
1615
this.visibleRows = rows;
1716
this.visibleRowIndices = rows.map(row => row.meta.rowIndex);
18-
17+
this.instance.noData = false;
1918
if (rows.length === 0) {
2019
this.bodyScrollable.innerHTML = this.getNoDataHTML();
20+
this.instance.noData = true;
2121
this.footer.innerHTML = '';
2222
return;
2323
}
@@ -140,7 +140,18 @@ export default class BodyRenderer {
140140
}
141141

142142
getNoDataHTML() {
143-
return `<div class="dt-scrollable__no-data">${this.options.noDataMessage}</div>`;
143+
const width = this.instance.header.scrollWidth;
144+
const height = this.bodyScrollable.clientHeight;
145+
return `
146+
<div
147+
class="dt-scrollable__no-data"
148+
style="width: ${width - 2}px; height: ${height}px"
149+
>
150+
<div class="dt-scrollable__no-data no-data-message">
151+
${this.options.noDataMessage}
152+
</div>
153+
</div>
154+
`;
144155
}
145156

146157
getToastMessageHTML(message) {

src/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
--dt-selection-highlight-color: var(--dt-light-yellow);
1717
--dt-toast-message-border: none;
1818
--dt-header-cell-bg: var(--dt-cell-bg);
19+
--dt-no-data-message-width: 90px;
1920
}
2021

2122
.datatable {
@@ -54,7 +55,15 @@
5455
padding: var(--dt-spacer-3);
5556
border-left: 1px solid var(--dt-border-color);
5657
border-right: 1px solid var(--dt-border-color);
58+
.no-data-message{
59+
position: absolute;
60+
top: 100px;
61+
left: 50px;
62+
border: none;
63+
width: var(--dt-no-data-message-width);
64+
}
5765
}
66+
5867
}
5968

6069
.dt-row {

src/style.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class Style {
7777
// Find corresponding footer cell
7878
const footerCell = this.footer.querySelector(`.dt-cell[data-col-index="${colIndex}"]`);
7979

80-
if (~~(bodyCell.offsetLeft - scrollLeft) > colLeft) {
80+
if (bodyCell && ~~(bodyCell.offsetLeft - scrollLeft) > colLeft) {
8181
headerCell.style.transform = `translateX(${-scrollLeft - 1}px)`;
8282
if (footerCell) {
8383
footerCell.style.transform = `translateX(${scrollLeft ? -scrollLeft - 1 : 0}px)`;
@@ -89,6 +89,12 @@ export default class Style {
8989
});
9090

9191
this._settingHeaderPosition = false;
92+
if (this.instance.noData) {
93+
$.style($('.no-data-message'), {
94+
left: `${this.instance.wrapper.clientWidth / 2 - (-scrollLeft)}px`
95+
});
96+
}
97+
this._settingHeaderPosition = false;
9298
});
9399
});
94100
}

0 commit comments

Comments
 (0)