feat: export-excel 的 columns 支持变量 (#3721)

This commit is contained in:
吴多益 2022-03-10 15:34:33 +08:00 committed by GitHub
parent 0a2c5e76a5
commit 4cf6a6fafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 2 deletions

View File

@ -1809,6 +1809,55 @@ crud 组件支持通过配置`headerToolbar`和`footerToolbar`属性,实现在
}
```
> 1.8.0 及以上版本
`columns` 支持变量,可以从上下文取数组
```schema
{
"type": "page",
"data": {
"columns": ["engine", "browser"]
},
"body": {
"type": "crud",
"syncLocation": false,
"api": "/api/mock2/sample",
"headerToolbar": [{
"type": "export-excel",
"label": "只导出 engine 和 browser 列",
"columns": "${columns}"
}],
"columns": [
{
"name": "id",
"label": "ID"
},
{
"name": "engine",
"label": "Rendering engine"
},
{
"name": "browser",
"label": "Browser"
},
{
"name": "platform",
"label": "Platform(s)"
},
{
"name": "version",
"label": "Engine version"
},
{
"name": "grade",
"label": "CSS grade"
}
]
}
}
```
#### 通过 api 导出 Excel
> 1.1.6 以上版本支持

View File

@ -2310,9 +2310,18 @@ export default class Table extends React.Component<TableProps, object> {
});
worksheet.views = [{state: 'frozen', xSplit: 0, ySplit: 1}];
const filteredColumns = toolbar.columns
let exportColumns = toolbar.columns;
if (isPureVariable(exportColumns)) {
exportColumns = resolveVariableAndFilter(
exportColumns,
data,
'| raw'
);
}
const filteredColumns = exportColumns
? columns.filter(column => {
const filterColumnsNames = toolbar.columns!;
const filterColumnsNames = exportColumns!;
if (filterColumnsNames.indexOf(column.name) !== -1) {
return true;
}