Skip to content

Commit 75ab431

Browse files
committed
Better empty text in fixed columns table
close ant-design/ant-design#7298 close ant-design/ant-design#7142
1 parent ffb89f5 commit 75ab431

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

assets/index.less

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@
6666
border-bottom: 1px solid @table-border-color;
6767
text-align: center;
6868
position: relative;
69+
&-fixed-columns {
70+
position: absolute;
71+
bottom: 0;
72+
width: 100%;
73+
background: transparent;
74+
pointer-events: none;
75+
}
6976
}
7077

7178
table {
@@ -82,6 +89,10 @@
8289

8390
td {
8491
border-bottom: 1px solid @table-border-color;
92+
&:empty:after {
93+
content: '.'; // empty cell placeholder
94+
visibility: hidden;
95+
}
8596
}
8697

8798
tr {

examples/fixedColumns.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,13 @@ const columns = [
1919
{ title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' },
2020
];
2121

22-
const data = [
23-
{ a: '123', b: 'xxxxxxxx', d: 3, key: '1' },
24-
{ a: 'cdd', b: 'edd12221', d: 3, key: '2' },
25-
{ a: '133', c: 'edd12221', d: 2, key: '3' },
26-
{ a: '133', c: 'edd12221', d: 2, key: '4' },
27-
{ a: '133', c: 'edd12221', d: 2, key: '5' },
28-
{ a: '133', c: 'edd12221', d: 2, key: '6' },
29-
{ a: '133', c: 'edd12221', d: 2, key: '7' },
30-
{ a: '133', c: 'edd12221', d: 2, key: '8' },
31-
{ a: '133', c: 'edd12221', d: 2, key: '9' },
32-
];
22+
const data = [];
3323

3424
ReactDOM.render(
3525
<div style={{ width: 800 }}>
3626
<h2>Fixed columns</h2>
3727
<Table
3828
columns={columns}
39-
expandedRowRender={record => record.title}
40-
expandIconAsCell
4129
scroll={{ x: 1200 }}
4230
data={data}
4331
/>

examples/fixedColumnsAndHeader.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,7 @@ const columns = [
1919
{ title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' },
2020
];
2121

22-
const data = [
23-
{ a: 'aaa', b: 'bbb', c: '内容内容内容内容内容', d: 3, key: '1' },
24-
{ a: 'aaa', b: 'bbb', c: '内容内容内容内容内容', d: 3, key: '2' },
25-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '3' },
26-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '4' },
27-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '5' },
28-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '6' },
29-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '7' },
30-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '8' },
31-
{ a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '9' },
32-
];
22+
const data = [];
3323

3424
ReactDOM.render(
3525
<div>

src/Table.jsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export default class Table extends React.Component {
294294
);
295295
}
296296

297-
getRowsByData(data, visible, indent, columns, fixed) {
297+
getRowsByData(originalData, visible, indent, columns, fixed) {
298298
const props = this.props;
299299
const {
300300
childrenColumnName,
@@ -315,7 +315,10 @@ export default class Table extends React.Component {
315315

316316
const expandIconAsCell = fixed !== 'right' ? props.expandIconAsCell : false;
317317
const expandIconColumnIndex = fixed !== 'right' ? props.expandIconColumnIndex : -1;
318-
318+
let data = originalData;
319+
if (this.columnManager.isAnyColumnsFixed() && data.length === 0) {
320+
data = [{ key: 'empty-placeholder-data' }];
321+
}
319322
for (let i = 0; i < data.length; i++) {
320323
const record = data[i];
321324
const key = this.getRowKey(record, i);
@@ -571,11 +574,17 @@ export default class Table extends React.Component {
571574

572575
getEmptyText() {
573576
const { emptyText, prefixCls, data } = this.props;
574-
return !data.length ? (
575-
<div className={`${prefixCls}-placeholder`} key="emptyText">
577+
if (data.length) {
578+
return null;
579+
}
580+
const fixed = this.columnManager.isAnyColumnsFixed();
581+
const emptyClassName =
582+
`${prefixCls}-placeholder${fixed ? ` ${prefixCls}-placeholder-fixed-columns` : ''}`;
583+
return (
584+
<div className={emptyClassName} key="emptyText">
576585
{(typeof emptyText === 'function') ? emptyText() : emptyText}
577586
</div>
578-
) : null;
587+
);
579588
}
580589

581590
getHeaderRowStyle(columns, rows) {

0 commit comments

Comments
 (0)