fix(useColumns): 多级表头下的列支持行内编辑 (#2521)
This commit is contained in:
parent
0dc2f1496b
commit
f7a1b02236
|
|
@ -146,31 +146,38 @@ export function useColumns(
|
||||||
const getViewColumns = computed(() => {
|
const getViewColumns = computed(() => {
|
||||||
const viewColumns = sortFixedColumn(unref(getColumnsRef));
|
const viewColumns = sortFixedColumn(unref(getColumnsRef));
|
||||||
|
|
||||||
|
const mapFn = (column) => {
|
||||||
|
const { slots, customRender, format, edit, editRow, flag } = column;
|
||||||
|
|
||||||
|
if (!slots || !slots?.title) {
|
||||||
|
// column.slots = { title: `header-${dataIndex}`, ...(slots || {}) };
|
||||||
|
column.customTitle = column.title;
|
||||||
|
Reflect.deleteProperty(column, 'title');
|
||||||
|
}
|
||||||
|
const isDefaultAction = [INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG].includes(flag!);
|
||||||
|
if (!customRender && format && !edit && !isDefaultAction) {
|
||||||
|
column.customRender = ({ text, record, index }) => {
|
||||||
|
return formatCell(text, format, record, index);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// edit table
|
||||||
|
if ((edit || editRow) && !isDefaultAction) {
|
||||||
|
column.customRender = renderEditCell(column);
|
||||||
|
}
|
||||||
|
return reactive(column);
|
||||||
|
};
|
||||||
|
|
||||||
const columns = cloneDeep(viewColumns);
|
const columns = cloneDeep(viewColumns);
|
||||||
return columns
|
return columns
|
||||||
.filter((column) => {
|
.filter((column) => hasPermission(column.auth) && isIfShow(column))
|
||||||
return hasPermission(column.auth) && isIfShow(column);
|
|
||||||
})
|
|
||||||
.map((column) => {
|
.map((column) => {
|
||||||
const { slots, customRender, format, edit, editRow, flag } = column;
|
// Support table multiple header editable
|
||||||
|
if (column.children?.length) {
|
||||||
if (!slots || !slots?.title) {
|
column.children = column.children.map(mapFn);
|
||||||
// column.slots = { title: `header-${dataIndex}`, ...(slots || {}) };
|
|
||||||
column.customTitle = column.title;
|
|
||||||
Reflect.deleteProperty(column, 'title');
|
|
||||||
}
|
|
||||||
const isDefaultAction = [INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG].includes(flag!);
|
|
||||||
if (!customRender && format && !edit && !isDefaultAction) {
|
|
||||||
column.customRender = ({ text, record, index }) => {
|
|
||||||
return formatCell(text, format, record, index);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit table
|
return mapFn(column);
|
||||||
if ((edit || editRow) && !isDefaultAction) {
|
|
||||||
column.customRender = renderEditCell(column);
|
|
||||||
}
|
|
||||||
return reactive(column);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,47 +29,54 @@
|
||||||
const columns: BasicColumn[] = [
|
const columns: BasicColumn[] = [
|
||||||
{
|
{
|
||||||
title: '输入框',
|
title: '输入框',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name-group',
|
||||||
editRow: true,
|
editRow: true,
|
||||||
editComponentProps: {
|
children: [
|
||||||
prefix: '$',
|
{
|
||||||
},
|
title: '输入框',
|
||||||
width: 150,
|
dataIndex: 'name',
|
||||||
},
|
editRow: true,
|
||||||
{
|
editComponentProps: {
|
||||||
title: '默认输入状态',
|
prefix: '$',
|
||||||
dataIndex: 'name7',
|
},
|
||||||
editRow: true,
|
width: 150,
|
||||||
width: 150,
|
},
|
||||||
},
|
{
|
||||||
{
|
title: '默认输入状态',
|
||||||
title: '输入框校验',
|
dataIndex: 'name7',
|
||||||
dataIndex: 'name1',
|
editRow: true,
|
||||||
editRow: true,
|
width: 150,
|
||||||
align: 'left',
|
},
|
||||||
// 默认必填校验
|
{
|
||||||
editRule: true,
|
title: '输入框校验',
|
||||||
width: 150,
|
dataIndex: 'name1',
|
||||||
},
|
editRow: true,
|
||||||
{
|
align: 'left',
|
||||||
title: '输入框函数校验',
|
// 默认必填校验
|
||||||
dataIndex: 'name2',
|
editRule: true,
|
||||||
editRow: true,
|
width: 150,
|
||||||
align: 'right',
|
},
|
||||||
editRule: async (text) => {
|
{
|
||||||
if (text === '2') {
|
title: '输入框函数校验',
|
||||||
return '不能输入该值';
|
dataIndex: 'name2',
|
||||||
}
|
editRow: true,
|
||||||
return '';
|
align: 'right',
|
||||||
},
|
editRule: async (text) => {
|
||||||
},
|
if (text === '2') {
|
||||||
{
|
return '不能输入该值';
|
||||||
title: '数字输入框',
|
}
|
||||||
dataIndex: 'id',
|
return '';
|
||||||
editRow: true,
|
},
|
||||||
editRule: true,
|
},
|
||||||
editComponent: 'InputNumber',
|
{
|
||||||
width: 150,
|
title: '数字输入框',
|
||||||
|
dataIndex: 'id',
|
||||||
|
editRow: true,
|
||||||
|
editRule: true,
|
||||||
|
editComponent: 'InputNumber',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '下拉框',
|
title: '下拉框',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue