feat(data-table): add allowExport prop for column (#5925)

* feat(data-table): add allowExport prop for column

* docs: update CHANGELOG.en-US.md

---------

Co-authored-by: 07akioni <07akioni2@gmail.com>
This commit is contained in:
FuNi 2024-08-11 21:43:42 +08:00 committed by GitHub
parent b2eb69e534
commit c30e3c6e61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 2 deletions

View File

@ -36,6 +36,7 @@
- `n-empty` `size` prop to support `tiny` size.
- `n-config-provider` adds `style-mount-target` prop to control where to mount components' style.
- `n-cascader` filter ignore case sensitive
- `n-data-table` add allowExport prop for column
## 2.39.0
@ -72,7 +73,7 @@
- Fix `n-menu` Submenu's wai-aria role is not correct, closes [#5729](https://github.com/tusen-ai/naive-ui/issues/5729).
- Fix `n-tabs` style bug with type is `segment`closes [#5728](https://github.com/tusen-ai/naive-ui/issues/5728).
- Fix the get\*String() methods for UTC/locale mismatch, closes [#5702](closes https://github.com/tusen-ai/naive-ui/issues/5702).
- Fix the get\*String() methods for UTC/locale mismatch, closes [#5702](https://github.com/tusen-ai/naive-ui/issues/5702).
- Fix `n-dialog` / `n-modal` calling `destroy` method may throw error.
- Fix `useModal` setting `card` preset without corresponding props in `n-card` slots, closes [#5746](https://github.com/tusen-ai/naive-ui/issues/5746).
- Fix `Submenu` component's wai-aria role setting error of `n-menu`closes [#5729](https://github.com/tusen-ai/naive-ui/issues/5729).

View File

@ -36,6 +36,7 @@
- `n-empty` `size` 支持 `tiny` 尺寸
- `n-config-provider` 新增 `style-mount-target` 属性,用于控制样式的挂载位置
- `n-cascader` 过滤算法忽略大小写
- `n-data-table` 在列的配置中新增是否导出的属性
## 2.39.0

View File

@ -131,6 +131,7 @@ export-csv.vue
| disabled | `(rowData: object, rowIndex: number) => boolean` | `() => false` | Whether the row is checkable. | |
| ellipsis | `boolean \| EllipsisProps` | `false` | Ellipsis options when content overflows. | |
| ellipsis-component | `'ellipsis' \| 'performant-ellipsis'` | `'ellipsis'` | Component for rendering text ellipsis. It works when `ellipsis` is `EllipsisProps`. If it's `'ellipsis'`, table will use regular `n-ellipsis` component to render text ellipsis. If it's `'performant-ellipsis'`, table will use `n-performant-ellipsis` to render text ellipsis. In the later situation, rendering speed will be much faster but component inside table cell would be unmounted & remounted. | 2.35.0 |
| allowExport | `boolean` | `true` | Can the column exported | NEXT_VERSION |
| expandable | `(rowData: object) => boolean` | `undefined` | Whethe the row is expandable. Only works when `type` is `'expand'`. | |
| filter | `boolean \| (optionValue: string \| number, rowData: object) => boolean \| 'default'` | `false` | The filter of the column. If set to `true`, it will only display filter button on the column, which can be used in async status. | |
| filterMode | `'and' \| 'or'` | `'or'` | The filter mode. | |

View File

@ -142,6 +142,7 @@ rtl-debug.vue
| disabled | `(rowData: object, rowIndex: number) => boolean` | `undefined` | 是否禁用 | |
| ellipsis | `boolean \| EllipsisProps` | `false` | 文本溢出的设置 | |
| ellipsis-component | `'ellipsis' \| 'performant-ellipsis'` | `'ellipsis'` | 渲染文本溢出时使用的组件,在 `ellipsis` 属性为 `EllipsisProps` 时生效。若为 `'ellipsis'` 则使用常规的 `n-ellipsis` 组件渲染,若为 `'performant-ellipsis'` 则使用 `n-performant-ellipsis` 渲染,这种情况下会有更高的渲染性能,但是每个折叠的单元格中的组件有可能被重新卸载和挂载 | 2.35.0 |
| allowExport | `boolean` | `true` | 这一列是否可以导出 | NEXT_VERSION |
| expandable | `(rowData: object) => boolean` | `undefined` | 行是否可展开,仅在 `type``'expand'` 时生效 | |
| filter | `boolean \| (optionValue: string \| number, rowData: object) => boolean \| 'default'` | `undefined` | 这一列的过滤方法。如果设为 `true`,表格将只会在这列展示一个排序图标,在异步的时候可能有用。 | |
| filterMode | `'and' \| 'or'` | `'or'` | 同一列筛选方式为与还是或 | |

View File

@ -227,6 +227,7 @@ export interface CommonColumnInfo<T = InternalRowData> {
titleAlign?: 'left' | 'center' | 'right'
ellipsis?: Ellipsis
ellipsisComponent?: 'ellipsis' | 'performant-ellipsis'
allowExport?: boolean
cellProps?: (rowData: T, rowIndex: number) => HTMLAttributes
}

View File

@ -207,7 +207,10 @@ function formatCsvCell(value: unknown): string {
export function generateCsv(columns: TableColumn[], data: RowData[]): string {
const exportableColumns = columns.filter(
column => column.type !== 'expand' && column.type !== 'selection'
(column) =>
column.type !== 'expand' &&
column.type !== 'selection' &&
column.allowExport !== false
)
const header = exportableColumns.map((col: any) => col.title).join(',')
const rows = data.map((row) => {