From 602ab98f802e525794066bcbb057859b49e6b222 Mon Sep 17 00:00:00 2001 From: zhangwenshuai Date: Tue, 2 Jun 2020 11:02:29 +0800 Subject: [PATCH] update apolloTable --- components/apolloTable/component/Column.tsx | 10 ++++++---- components/apolloTable/component/Table.tsx | 14 +++++++------- components/apolloTable/component/index.tsx | 4 ++++ components/apolloTable/component/interface.tsx | 2 ++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/components/apolloTable/component/Column.tsx b/components/apolloTable/component/Column.tsx index dfe3481..6d18832 100644 --- a/components/apolloTable/component/Column.tsx +++ b/components/apolloTable/component/Column.tsx @@ -48,7 +48,9 @@ export default class TableColumn extends PureComponent { if (typeof onChange === 'function') { const data = _.cloneDeep(selectedRows); dataSource.map((item: any) => { - const index = data.findIndex((temp: any) => { return temp.id === item.id; }); + const index = data.findIndex((temp: any) => { + return temp.id === item.id; + }); if (checked) { index > -1 && data.splice(index, 1); } else { @@ -72,6 +74,7 @@ export default class TableColumn extends PureComponent { columnIndex, questionText, rowSelection, + icon, } = this.props; const { value = [] } = sortConfig || {}; const sort = value.find((item: any) => { @@ -82,13 +85,12 @@ export default class TableColumn extends PureComponent {
{rowSelection && columnIndex === 0 &&
{this.getCheckbox()}
}
+ {icon &&
{icon()}
} {columnChsName} {questionText && ( -
- ? -
+
?
)}
diff --git a/components/apolloTable/component/Table.tsx b/components/apolloTable/component/Table.tsx index 7bec9ac..2c716e2 100644 --- a/components/apolloTable/component/Table.tsx +++ b/components/apolloTable/component/Table.tsx @@ -55,7 +55,7 @@ export default class AirTable extends Component { constructor(props: TableProps) { super(props); - const { columns, dataSource, width = 0, height = 0, rowHeight } = props; + const { columns, dataSource, width = 0, height = 0, rowHeight, headerHeight, columnWidth } = props; this.state = { columns, dataSource, @@ -65,9 +65,9 @@ export default class AirTable extends Component { this.config = { overscanColumnCount: 5, overscanRowCount: 5, - columnWidth: 150, + columnWidth: columnWidth || 150, rowHeight: rowHeight || 80, - headerHeight: 60, + headerHeight: headerHeight || 60, }; this.memoizeLeftColumns = memoizeOne(this.getLeftColumns); this.memoizeRightColumns = memoizeOne(this.getRightColumns); @@ -214,6 +214,7 @@ export default class AirTable extends Component { columnAttrObj = {}, sortFlag, questionText, + icon, } = showColumns[columnIndex]; return (
@@ -229,6 +230,7 @@ export default class AirTable extends Component { questionText={questionText} rowSelection={position === 'right' ? false : rowSelection} dataSource={dataSource} + icon={icon} />
); @@ -352,7 +354,7 @@ export default class AirTable extends Component { const rightWidth = this.memoizeLeftWidth(rightColumns, showColumns); let totalHeight: number = rowCount * rowHeight; const { totalWidth } = this.memoizeTotalWidth(showColumns); - if (totalWidth > tableWidth) { + if (rowCount > 0 && totalWidth > tableWidth) { totalHeight = rowCount * rowHeight + scrollbarWidth; } return ( @@ -581,9 +583,7 @@ export default class AirTable extends Component {
)}
-
- {/**/} -
+
{/**/}
); }} diff --git a/components/apolloTable/component/index.tsx b/components/apolloTable/component/index.tsx index 8f17f18..f62c432 100644 --- a/components/apolloTable/component/index.tsx +++ b/components/apolloTable/component/index.tsx @@ -58,6 +58,8 @@ class AirTable extends React.Component { rowSelection, tableOperateConfig, noDataPlaceholder, + columnWidth, + headerHeight, } = this.props; const sortConfig = operateConfig && operateConfig.menusGroup @@ -86,6 +88,8 @@ class AirTable extends React.Component { emptyPlaceholder={emptyPlaceholder} cellEditable={cellEditable} rowHeight={rowHeight} + headerHeight={headerHeight} + columnWidth={columnWidth} loading={loading} rowSelection={rowSelection} noDataPlaceholder={noDataPlaceholder} diff --git a/components/apolloTable/component/interface.tsx b/components/apolloTable/component/interface.tsx index 833dc7e..afe2a22 100644 --- a/components/apolloTable/component/interface.tsx +++ b/components/apolloTable/component/interface.tsx @@ -65,6 +65,8 @@ export interface TableProps extends LoadConfigProps { emptyPlaceholder?: string; cellEditable?: boolean; rowHeight?: number; + headerHeight?: number; + columnWidth?: number; loading?: boolean; rowSelection?: any; noDataPlaceholder?: any; -- 2.21.0