diff --git a/components/apolloTable/component/DragFixed.tsx b/components/apolloTable/component/DragFixed.tsx index d32cbfa4a033eaa1fb6eaead140d360a6f3f5439..5cd089e528168a86a21bd784747e043242a46161 100644 --- a/components/apolloTable/component/DragFixed.tsx +++ b/components/apolloTable/component/DragFixed.tsx @@ -106,25 +106,31 @@ const DragFixed = (props: any) => { let leftFixedWidth = 0; const fixedCol: any = {}; + const fixedColOrder: any = []; // 计算获取固定列 for (let i = 0; i < showColumns.length; i++) { leftFixedWidth += showColumns[i].width || columnWidth; if (leftFixedWidth <= Number(fixedWidthNum)) { - fixedCol[showColumns[i].columnName] = 1; + fixedColOrder.push(showColumns[i].columnName); + // 固定列修改排序到最前面 + fixedCol[showColumns[i].columnName] = { + ...showColumns[i], + fixed: 'left', + orderNo: i + 1, + }; } else { break; } } - const newColumns: any = []; + let newColumns: any = []; + fixedColOrder.map((temp:any) => { + newColumns.push(fixedCol[temp]); + }); + // 新的列数组包含刚固定的列(排在最前面)和原来的所有列,需要将后面重复的列剔除 + newColumns = newColumns.concat(columns); + // 为固定列增加fixed属性 - columns.map((item: any) => { - if (fixedCol[item.columnName] === 1) { - item.fixed = 'left'; - } else { - if (!!item.showStatus && item.fixed === 'left') { - item.fixed = ''; - } - } + const updateCache = (item: any) => { // 缓存 if (cachedFeAttr) { const cachedCols = getCache({ tableId }); @@ -132,19 +138,38 @@ const DragFixed = (props: any) => { cachedCols[item.columnName] = { ...cachedCols[item.columnName], fixed: item.fixed, + orderNo: item.orderNo, }; saveCache({ tableId, data: cachedCols }); } } - newColumns.push(item); + }; + const sortedColumns: any = []; + newColumns.map((item: any, i: number) => { + if (i >= fixedColOrder.length) { + // 除了新增加的固定列,之前的固定列都还原为未固定 + if (item.fixed === 'left') { + item.fixed = ''; + } + // 剔除重复列 + if (!fixedCol[item.columnName]) { + // 重新排序 + item.orderNo = sortedColumns.length + 1; + updateCache(item); + sortedColumns.push(item); + } + } else { + updateCache(item); + sortedColumns.push(item); + } }); // 业务回调 if (typeof onDragFixed === 'function') { - onDragFixed(newColumns); + onDragFixed(sortedColumns); } // table回调 if (typeof onResizeStop === 'function') { - onResizeStop(newColumns); + onResizeStop(sortedColumns); } }; diff --git a/components/apolloTable/component/Table.tsx b/components/apolloTable/component/Table.tsx index 9112c0dd5cb7a7e50480ecc3077c2a8a23a65e35..9dc827741f0c3b508e8dab8f1af15e96a9b45ce9 100644 --- a/components/apolloTable/component/Table.tsx +++ b/components/apolloTable/component/Table.tsx @@ -539,7 +539,7 @@ export default class AirTable extends Component { tableWidth={tableWidth} showColumns={showColumns} columnWidth={columnWidth} - columns={columns} + columns={formatColumns} onResizeStart={this.onResizeStartLeftDragFixed} onResizeStop={this.onResizeStopLeftDragFixed} onDragFixed={onDragFixed} @@ -637,7 +637,7 @@ export default class AirTable extends Component { }} - {canFixed && ( + {false && ( { tableWidth={tableWidth} showColumns={showColumns} columnWidth={columnWidth} - columns={columns} + columns={formatColumns} paddingRight={paddingRight} onResizeStart={this.onResizeStartRightDragFixed} onResizeStop={this.onResizeStopRightDragFixed}