修复表格展开收起可能出现的报错问题

This commit is contained in:
2betop 2021-04-25 17:25:22 +08:00
parent 019ca97614
commit c433b794b1
2 changed files with 33 additions and 16 deletions

View File

@ -450,7 +450,7 @@
content: '';
position: absolute;
height: px2rem(1px);
top: px2rem(18px);
top: 50%;
left: px2rem(-8px) + px2rem(18px) * ($i - 2);
width: px2rem(10px);
background: var(--Table-tree-borderColor);
@ -469,7 +469,7 @@
tr.#{$ns}Table-tr--#{$i}th.is-last:not(.is-expanded) {
.#{$ns}Table-expandCell + td {
&::before {
height: px2rem(18px);
height: 50%;
bottom: auto;
}
}
@ -525,7 +525,7 @@
content: '';
position: absolute;
width: px2rem(1px);
top: px2rem(28px);
top: 50%;
bottom: 0;
right: px2rem(7px);
height: auto;

View File

@ -25,7 +25,8 @@ import {
difference,
immutableExtends,
extendObject,
hasVisibleExpression
hasVisibleExpression,
filterTree
} from '../utils/helper';
import {evalExpression} from '../utils/tpl';
import {IFormStore} from './form';
@ -255,7 +256,7 @@ export const TableStore = iRendererStore
columns: types.array(Column),
rows: types.array(Row),
selectedRows: types.array(types.reference(Row)),
expandedRows: types.array(types.reference(Row)),
expandedRows: types.array(types.string),
primaryField: 'id',
orderBy: '',
orderDir: types.optional(
@ -356,7 +357,7 @@ export const TableStore = iRendererStore
}
function isExpanded(row: IRow): boolean {
return !!~self.expandedRows.indexOf(row);
return self.expandedRows.includes(row.id);
}
function getTogglable() {
@ -589,6 +590,18 @@ export const TableStore = iRendererStore
return this.forms
.filter(form => form.rowIndex === parseInt(name, 10))
.map(item => item.store);
},
getExpandedRows() {
const list: Array<IRow> = [];
eachTree(self.rows, i => {
if (self.expandedRows.includes(i.id)) {
list.push(i as any);
}
});
return list;
}
};
})
@ -829,14 +842,14 @@ export const TableStore = iRendererStore
expand === 'first' ||
(self.expandConfig && self.expandConfig.expand === 'first')
) {
self.rows.length && self.expandedRows.push(self.rows[0]);
self.rows.length && self.expandedRows.push(self.rows[0].id);
} else if (
(expand === 'all' && !self.footable.accordion) ||
(self.expandConfig &&
self.expandConfig.expand === 'all' &&
!self.expandConfig.accordion)
) {
self.expandedRows.replace(self.rows);
self.expandedRows.replace(self.rows.map(item => item.id));
}
self.dragging = false;
@ -957,29 +970,33 @@ export const TableStore = iRendererStore
if (self.allExpanded) {
self.expandedRows.clear();
} else {
self.expandedRows.replace(self.rows.filter(item => item.expandable));
self.expandedRows.replace(
self.rows.filter(item => item.expandable).map(item => item.id)
);
}
}
function toggleExpanded(row: IRow) {
const idx = self.expandedRows.indexOf(row);
const idx = self.expandedRows.indexOf(row.id);
if (~idx) {
self.expandedRows.splice(idx, 1);
} else if (self.footable && self.footable.accordion) {
self.expandedRows.replace([row]);
self.expandedRows.replace([row.id]);
} else if (self.expandConfig && self.expandConfig.accordion) {
let rows = self.expandedRows.filter(item => item.depth !== row.depth);
let rows = self
.getExpandedRows()
.filter(item => item.depth !== row.depth);
rows.push(row);
self.expandedRows.replace(rows);
self.expandedRows.replace(rows.map(item => item.id));
} else {
self.expandedRows.push(row);
self.expandedRows.push(row.id);
}
}
function collapseAllAtDepth(depth: number) {
let rows = self.expandedRows.filter(item => item.depth !== depth);
self.expandedRows.replace(rows);
let rows = self.getExpandedRows().filter(item => item.depth !== depth);
self.expandedRows.replace(rows.map(item => item.id));
}
function setOrderByInfo(key: string, direction: 'asc' | 'desc') {