Commit cf013df5 authored by zhangwenshuai's avatar zhangwenshuai

左侧固定列可滑动

parent 6f2e5aeb
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
position: absolute; position: absolute;
left: 0; left: 0;
z-index: 1; z-index: 1;
overflow: hidden;
} }
.centerContainer { .centerContainer {
display: flex; display: flex;
...@@ -55,14 +56,13 @@ ...@@ -55,14 +56,13 @@
} }
.sideGrid { .sideGrid {
overflow: hidden !important; //overflow: hidden !important;
outline: none; outline: none;
} }
.centerGrid { .centerGrid {
outline: none; outline: none;
} }
.bodyRow { .bodyRow {
} }
.bodyCell { .bodyCell {
font-size: 20px; font-size: 20px;
...@@ -103,17 +103,34 @@ ...@@ -103,17 +103,34 @@
left: 0; left: 0;
right: 0; right: 0;
pointer-events: none; pointer-events: none;
z-index: 2;
} }
.defaultEmpty { .defaultEmpty {
padding-top: 100px; padding-top: 100px;
} }
.handleWidth{ .widthHandleWrapper {
position: absolute;
cursor: ew-resize;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.4);
z-index: 20;
display: none;
.widthHandle {
position: absolute;
cursor: ew-resize;
width: 2px;
height: 100%;
background-color: rgb(33, 150, 243);
}
}
.handleWidth {
position: absolute; position: absolute;
width: 10px; width: 2px;
height: 100%; height: 100%;
bottom: 0; bottom: 0;
right: -5px; right: -1px;
cursor: col-resize; cursor: ew-resize;
z-index: 1; z-index: 1;
background: #ececec; background: #ececec;
} }
...@@ -3,7 +3,7 @@ import classNames from 'classnames'; ...@@ -3,7 +3,7 @@ import classNames from 'classnames';
import memoizeOne from 'memoize-one'; import memoizeOne from 'memoize-one';
import { Empty, Spin } from 'antd'; import { Empty, Spin } from 'antd';
import { ScrollSync, Grid, AutoSizer } from 'react-virtualized'; import { ScrollSync, Grid, AutoSizer } from 'react-virtualized';
import { Resizable } from 'react-resizable'; import { Resizable, ResizableBox } from 'react-resizable';
import _ from 'lodash'; import _ from 'lodash';
import scrollbarSize from 'dom-helpers/scrollbarSize'; import scrollbarSize from 'dom-helpers/scrollbarSize';
import styles from './Table.less'; import styles from './Table.less';
...@@ -29,6 +29,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -29,6 +29,7 @@ export default class AirTable extends Component<TableProps, TableState> {
grid5: any; grid5: any;
grid6: any; grid6: any;
tableContainer: any;
memoizeData: Function; memoizeData: Function;
...@@ -67,6 +68,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -67,6 +68,8 @@ export default class AirTable extends Component<TableProps, TableState> {
tableWidth: width, tableWidth: width,
tableHeight: height, tableHeight: height,
selectedCell: null, selectedCell: null,
showWidthHandle: false,
widthHandleLeft: 0,
}; };
this.config = { this.config = {
overscanColumnCount: 5, overscanColumnCount: 5,
...@@ -218,6 +221,33 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -218,6 +221,33 @@ export default class AirTable extends Component<TableProps, TableState> {
// 列伸缩回调 // 列伸缩回调
onResizeWidth = (columnName: string, e, { size }) => { onResizeWidth = (columnName: string, e, { size }) => {
let originLeft =
this.tableContainer && this.tableContainer.offsetParent.offsetParent.offsetParent.style.paddingLeft;
if (originLeft) {
originLeft = originLeft.replace(/[a-zA-Z]/gi, '');
} else {
originLeft = 0;
}
this.setState({
widthHandleLeft: e.x - originLeft,
});
};
// 列伸缩开始
onResizeWidthStart = (columnName: string, e, { size }) => {
let originLeft =
this.tableContainer && this.tableContainer.offsetParent.offsetParent.offsetParent.style.paddingLeft;
if (originLeft) {
originLeft = originLeft.replace(/[a-zA-Z]/gi, '');
} else {
originLeft = 0;
}
this.setState({
showWidthHandle: true,
widthHandleLeft: e.x - originLeft,
});
};
// 列伸缩结束
onResizeWidthStop = (columnName: string, e, { size }) => {
const { columns } = this.state; const { columns } = this.state;
const newColumns: any = []; const newColumns: any = [];
columns.map((item) => { columns.map((item) => {
...@@ -229,6 +259,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -229,6 +259,7 @@ export default class AirTable extends Component<TableProps, TableState> {
this.setState( this.setState(
{ {
columns: newColumns, columns: newColumns,
showWidthHandle: false,
}, },
() => { () => {
this.grid1 && this.grid1.recomputeGridSize(); this.grid1 && this.grid1.recomputeGridSize();
...@@ -259,7 +290,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -259,7 +290,8 @@ export default class AirTable extends Component<TableProps, TableState> {
requiredFlag, requiredFlag,
} = showColumns[columnIndex]; } = showColumns[columnIndex];
return ( return (
<Resizable <div className={styles.headerCell} key={key} style={style}>
<ResizableBox
width={style.width} width={style.width}
handle={ handle={
<span <span
...@@ -269,10 +301,11 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -269,10 +301,11 @@ export default class AirTable extends Component<TableProps, TableState> {
}} }}
/> />
} }
onResize={this.onResizeWidth.bind(this, columnName)} // onResize={this.onResizeWidth.bind(this, columnName)}
// onResizeStart={this.onResizeWidthStart.bind(this, columnName)}
onResizeStop={this.onResizeWidthStop.bind(this, columnName)}
draggableOpts={{ enableUserSelectHack: false }} draggableOpts={{ enableUserSelectHack: false }}
> >
<div className={styles.headerCell} key={key} style={style}>
<Column <Column
columnType={String(columnType)} columnType={String(columnType)}
columnName={columnName} columnName={columnName}
...@@ -288,8 +321,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -288,8 +321,8 @@ export default class AirTable extends Component<TableProps, TableState> {
icon={icon} icon={icon}
required={requiredFlag} required={requiredFlag}
/> />
</ResizableBox>
</div> </div>
</Resizable>
); );
}; };
...@@ -383,7 +416,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -383,7 +416,7 @@ export default class AirTable extends Component<TableProps, TableState> {
render() { render() {
const { loading, noDataPlaceholder, loadComp } = this.props; const { loading, noDataPlaceholder, loadComp } = this.props;
const { columns, dataSource, tableWidth = 0, tableHeight = 0 } = this.state; const { columns, dataSource, tableWidth = 0, tableHeight = 0, showWidthHandle, widthHandleLeft } = this.state;
const { overscanColumnCount, overscanRowCount, rowHeight, headerHeight } = this.config; const { overscanColumnCount, overscanRowCount, rowHeight, headerHeight } = this.config;
const scrollbarWidth = scrollbarSize() || 0; const scrollbarWidth = scrollbarSize() || 0;
const showColumns = this.memoizeColumns(columns); const showColumns = this.memoizeColumns(columns);
...@@ -428,6 +461,9 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -428,6 +461,9 @@ export default class AirTable extends Component<TableProps, TableState> {
style={{ style={{
paddingRight: this.props.onScroll ? paddingRight : 0, paddingRight: this.props.onScroll ? paddingRight : 0,
}} }}
ref={(dom) => {
this.tableContainer = dom;
}}
> >
{totalWidth > tableWidth && leftCount > 0 && ( {totalWidth > tableWidth && leftCount > 0 && (
<div <div
...@@ -489,8 +525,12 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -489,8 +525,12 @@ export default class AirTable extends Component<TableProps, TableState> {
columns: showColumns, columns: showColumns,
showColumns: leftColumns, showColumns: leftColumns,
})} })}
onScroll={(...arg: Array<Object>) => {
onScroll(...arg);
this.onScroll(arg[0]);
}}
columnCount={leftCount} columnCount={leftCount}
width={leftWidth} width={leftWidth + scrollbarWidth}
rowHeight={rowHeight} rowHeight={rowHeight}
rowCount={rowCount} rowCount={rowCount}
height={totalHeight - scrollbarWidth} height={totalHeight - scrollbarWidth}
...@@ -569,6 +609,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -569,6 +609,7 @@ export default class AirTable extends Component<TableProps, TableState> {
onScroll(...arg); onScroll(...arg);
this.onScroll(arg[0]); this.onScroll(arg[0]);
}} }}
scrollTop={scrollTop}
height={totalHeight} height={totalHeight}
cellRenderer={this.renderBodyCell.bind(this, { cellRenderer={this.renderBodyCell.bind(this, {
showColumns, showColumns,
...@@ -671,6 +712,12 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -671,6 +712,12 @@ export default class AirTable extends Component<TableProps, TableState> {
<div className={styles.loading} style={{ top: `${totalHeight / 2}px` }}> <div className={styles.loading} style={{ top: `${totalHeight / 2}px` }}>
{loading && (loadComp ? loadComp : <Spin />)} {loading && (loadComp ? loadComp : <Spin />)}
</div> </div>
<div
className={styles.widthHandleWrapper}
style={{ display: showWidthHandle ? 'block' : 'none' }}
>
<div className={styles.widthHandle} style={{ left: widthHandleLeft }} />
</div>
</div> </div>
); );
}} }}
......
...@@ -79,6 +79,8 @@ export interface TableState { ...@@ -79,6 +79,8 @@ export interface TableState {
tableHeight?: number; tableHeight?: number;
tableWidth?: number; tableWidth?: number;
selectedCell?: any; selectedCell?: any;
showWidthHandle: boolean;
widthHandleLeft: number;
} }
export interface CommonProps extends TableProps { export interface CommonProps extends TableProps {
operateConfig?: OperateConfigProps; operateConfig?: OperateConfigProps;
...@@ -120,7 +122,7 @@ export interface CellProps { ...@@ -120,7 +122,7 @@ export interface CellProps {
contentMenu?: any; contentMenu?: any;
selectedCell?: any; selectedCell?: any;
changeSelectedCell?: Function; changeSelectedCell?: Function;
position:string; position: string;
} }
export interface EditCellProps { export interface EditCellProps {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment