From 75ab43145400e64f3d7d0ec330a6407899e7864f Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 27 Aug 2017 17:01:17 +0800 Subject: [PATCH 1/2] Better empty text in fixed columns table close ant-design/ant-design#7298 close ant-design/ant-design#7142 --- assets/index.less | 11 +++++++++++ examples/fixedColumns.js | 14 +------------- examples/fixedColumnsAndHeader.js | 12 +----------- src/Table.jsx | 19 ++++++++++++++----- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/assets/index.less b/assets/index.less index 2fde62b95..173d5f1eb 100644 --- a/assets/index.less +++ b/assets/index.less @@ -66,6 +66,13 @@ border-bottom: 1px solid @table-border-color; text-align: center; position: relative; + &-fixed-columns { + position: absolute; + bottom: 0; + width: 100%; + background: transparent; + pointer-events: none; + } } table { @@ -82,6 +89,10 @@ td { border-bottom: 1px solid @table-border-color; + &:empty:after { + content: '.'; // empty cell placeholder + visibility: hidden; + } } tr { diff --git a/examples/fixedColumns.js b/examples/fixedColumns.js index ed05451dc..f8a6b7ee3 100644 --- a/examples/fixedColumns.js +++ b/examples/fixedColumns.js @@ -19,25 +19,13 @@ const columns = [ { title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' }, ]; -const data = [ - { a: '123', b: 'xxxxxxxx', d: 3, key: '1' }, - { a: 'cdd', b: 'edd12221', d: 3, key: '2' }, - { a: '133', c: 'edd12221', d: 2, key: '3' }, - { a: '133', c: 'edd12221', d: 2, key: '4' }, - { a: '133', c: 'edd12221', d: 2, key: '5' }, - { a: '133', c: 'edd12221', d: 2, key: '6' }, - { a: '133', c: 'edd12221', d: 2, key: '7' }, - { a: '133', c: 'edd12221', d: 2, key: '8' }, - { a: '133', c: 'edd12221', d: 2, key: '9' }, -]; +const data = []; ReactDOM.render(

Fixed columns

record.title} - expandIconAsCell scroll={{ x: 1200 }} data={data} /> diff --git a/examples/fixedColumnsAndHeader.js b/examples/fixedColumnsAndHeader.js index 88a8832d1..9a2450cf0 100644 --- a/examples/fixedColumnsAndHeader.js +++ b/examples/fixedColumnsAndHeader.js @@ -19,17 +19,7 @@ const columns = [ { title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' }, ]; -const data = [ - { a: 'aaa', b: 'bbb', c: '内容内容内容内容内容', d: 3, key: '1' }, - { a: 'aaa', b: 'bbb', c: '内容内容内容内容内容', d: 3, key: '2' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '3' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '4' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '5' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '6' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '7' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '8' }, - { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '9' }, -]; +const data = []; ReactDOM.render(
diff --git a/src/Table.jsx b/src/Table.jsx index a63763f59..1a4feff23 100644 --- a/src/Table.jsx +++ b/src/Table.jsx @@ -294,7 +294,7 @@ export default class Table extends React.Component { ); } - getRowsByData(data, visible, indent, columns, fixed) { + getRowsByData(originalData, visible, indent, columns, fixed) { const props = this.props; const { childrenColumnName, @@ -315,7 +315,10 @@ export default class Table extends React.Component { const expandIconAsCell = fixed !== 'right' ? props.expandIconAsCell : false; const expandIconColumnIndex = fixed !== 'right' ? props.expandIconColumnIndex : -1; - + let data = originalData; + if (this.columnManager.isAnyColumnsFixed() && data.length === 0) { + data = [{ key: 'empty-placeholder-data' }]; + } for (let i = 0; i < data.length; i++) { const record = data[i]; const key = this.getRowKey(record, i); @@ -571,11 +574,17 @@ export default class Table extends React.Component { getEmptyText() { const { emptyText, prefixCls, data } = this.props; - return !data.length ? ( -
+ if (data.length) { + return null; + } + const fixed = this.columnManager.isAnyColumnsFixed(); + const emptyClassName = + `${prefixCls}-placeholder${fixed ? ` ${prefixCls}-placeholder-fixed-columns` : ''}`; + return ( +
{(typeof emptyText === 'function') ? emptyText() : emptyText}
- ) : null; + ); } getHeaderRowStyle(columns, rows) { From 55828ff1ea99cb221db07211b7e3ba7b28696968 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 27 Aug 2017 17:06:37 +0800 Subject: [PATCH 2/2] revert examples --- examples/fixedColumns.js | 14 +++++++++++++- examples/fixedColumnsAndHeader.js | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/fixedColumns.js b/examples/fixedColumns.js index f8a6b7ee3..ed05451dc 100644 --- a/examples/fixedColumns.js +++ b/examples/fixedColumns.js @@ -19,13 +19,25 @@ const columns = [ { title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' }, ]; -const data = []; +const data = [ + { a: '123', b: 'xxxxxxxx', d: 3, key: '1' }, + { a: 'cdd', b: 'edd12221', d: 3, key: '2' }, + { a: '133', c: 'edd12221', d: 2, key: '3' }, + { a: '133', c: 'edd12221', d: 2, key: '4' }, + { a: '133', c: 'edd12221', d: 2, key: '5' }, + { a: '133', c: 'edd12221', d: 2, key: '6' }, + { a: '133', c: 'edd12221', d: 2, key: '7' }, + { a: '133', c: 'edd12221', d: 2, key: '8' }, + { a: '133', c: 'edd12221', d: 2, key: '9' }, +]; ReactDOM.render(

Fixed columns

record.title} + expandIconAsCell scroll={{ x: 1200 }} data={data} /> diff --git a/examples/fixedColumnsAndHeader.js b/examples/fixedColumnsAndHeader.js index 9a2450cf0..88a8832d1 100644 --- a/examples/fixedColumnsAndHeader.js +++ b/examples/fixedColumnsAndHeader.js @@ -19,7 +19,17 @@ const columns = [ { title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' }, ]; -const data = []; +const data = [ + { a: 'aaa', b: 'bbb', c: '内容内容内容内容内容', d: 3, key: '1' }, + { a: 'aaa', b: 'bbb', c: '内容内容内容内容内容', d: 3, key: '2' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '3' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '4' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '5' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '6' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '7' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '8' }, + { a: 'aaa', c: '内容内容内容内容内容', d: 2, key: '9' }, +]; ReactDOM.render(