Skip to content

Commit b9c2328

Browse files
committed
fix(Table): extra lock content enough space && dataSource=[], close#364
1 parent a9742df commit b9c2328

File tree

3 files changed

+89
-18
lines changed

3 files changed

+89
-18
lines changed

src/table/base.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ export default class Table extends React.Component {
130130
loading: PropTypes.bool,
131131
/**
132132
* 自定义 Loading 组件
133-
* @type {Function}
133+
* 请务必传递 props, 使用方式: loadingComponent={props => <Loading {...props}/>}
134+
* @param {Object} props 当前点击行的key
134135
*/
135136
loadingComponent: PropTypes.func,
136137
/**

src/table/lock.jsx

+47-17
Original file line numberDiff line numberDiff line change
@@ -347,31 +347,61 @@ export default function lock(BaseComponent) {
347347
}
348348
}
349349

350+
removeLockTable() {
351+
const lockLeftLen = this.lockLeftChildren.length;
352+
const lockRightLen = this.lockRightChildren.length;
353+
354+
if (lockLeftLen) {
355+
this._notNeedAdjustLockLeft = true;
356+
}
357+
if (lockRightLen) {
358+
this._notNeedAdjustLockRight = true;
359+
}
360+
if (lockRightLen || lockLeftLen) {
361+
this.forceUpdate();
362+
return true;
363+
}
364+
}
365+
350366
adjustIfTableNotNeedLock() {
351-
if (this.isOriginLock() && this.tableInc.props.dataSource.length) {
352-
const configWidths = this.tableInc.flatChildren
367+
if (this.isOriginLock()) {
368+
const widthObj = this.tableInc.flatChildren
353369
.map((item, index) => {
354-
const row = this.getCellNode(0, index);
355-
return (row && row.clientWidth) || 0;
370+
const cell = this.getCellNode(0, index) || {};
371+
const headerCell =
372+
this.getHeaderCellNode(0, index) || {};
373+
374+
return {
375+
cellWidths: cell.clientWidth || 0,
376+
headerWidths: headerCell.clientWidth || 0,
377+
};
356378
})
357-
.reduce((a, b) => a + b, 0);
379+
.reduce(
380+
(a, b) => {
381+
return {
382+
cellWidths: a.cellWidths + b.cellWidths,
383+
headerWidths: a.headerWidths + b.headerWidths,
384+
};
385+
},
386+
{
387+
cellWidths: 0,
388+
headerWidths: 0,
389+
}
390+
);
358391

359392
const node = findDOMNode(this);
360393
const width = node.clientWidth;
361-
const lockLeftLen = this.lockLeftChildren.length;
362-
const lockRightLen = this.lockRightChildren.length;
394+
395+
// if the table doesn't exist, there is no need to adjust
396+
if (width === 0) {
397+
return true;
398+
}
399+
400+
const configWidths =
401+
widthObj.cellWidths || widthObj.headerWidths;
363402

364403
if (configWidths <= width && configWidths > 0) {
365-
if (lockLeftLen) {
366-
this._notNeedAdjustLockLeft = true;
367-
}
368-
if (lockRightLen) {
369-
this._notNeedAdjustLockRight = true;
370-
}
371-
if (lockRightLen || lockLeftLen) {
372-
this.forceUpdate();
373-
return true;
374-
}
404+
this.removeLockTable();
375405
} else if (
376406
this._notNeedAdjustLockLeft ||
377407
this._notNeedAdjustLockRight

test/table/issue-spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,44 @@ describe('Issue', () => {
447447
ReactDOM.unmountComponentAtNode(div);
448448
document.body.removeChild(div);
449449
});
450+
451+
it('sort should have only one empty when datasorce=[] && enough width', () => {
452+
class App extends React.Component {
453+
render() {
454+
return (
455+
<Table
456+
style={{ width: '600px' }}
457+
dataSource={[]}
458+
scrollToRow={20}
459+
>
460+
<Table.Column
461+
title="Id1"
462+
lock
463+
dataIndex="id"
464+
width={100}
465+
/>
466+
<Table.Column
467+
title="Index"
468+
dataIndex="index"
469+
width={200}
470+
/>
471+
<Table.Column
472+
title="Time"
473+
dataIndex="time"
474+
lock="right"
475+
width={200}
476+
/>
477+
</Table>
478+
);
479+
}
480+
}
481+
482+
const div = document.createElement('div');
483+
document.body.appendChild(div);
484+
ReactDOM.render(<App />, div);
485+
486+
assert(document.querySelectorAll('div.next-table-empty').length === 1);
487+
ReactDOM.unmountComponentAtNode(div);
488+
document.body.removeChild(div);
489+
});
450490
});

0 commit comments

Comments
 (0)