From de8746e02d68fa68f55a16fe4afbe57e4221d49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Tue, 28 Jun 2022 22:26:21 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(table):=20=E6=96=B0=E5=A2=9E=20cellSt?= =?UTF-8?q?yle=20cellClassName=20rowStyle=20rowClassName=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7,=20=E7=94=A8=E4=BA=8E=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=A0=BC=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/component/table/TableRow.vue | 70 ++++++++++++++---- .../component/src/component/table/index.vue | 15 +++- .../src/document/zh-CN/components/table.md | 73 +++++++++++++++++++ 3 files changed, 144 insertions(+), 14 deletions(-) diff --git a/package/component/src/component/table/TableRow.vue b/package/component/src/component/table/TableRow.vue index a85ef8f6..3257358b 100644 --- a/package/component/src/component/table/TableRow.vue +++ b/package/component/src/component/table/TableRow.vue @@ -12,6 +12,7 @@ import LayDropdown from "../dropdown/index.vue"; import LayTooltip from "../tooltip/index.vue"; export interface LayTableRowProps { + index: number; indentSize: number; currentIndentSize: number; expandSpace: boolean; @@ -20,6 +21,10 @@ export interface LayTableRowProps { childrenColumnName?: string; columns: Recordable[]; checkbox?: boolean; + cellClassName: string | Function; + cellStyle: string | Function; + rowClassName: string | Function; + rowStyle: string | Function; id: string; data: any; } @@ -35,6 +40,8 @@ const emit = defineEmits([ const props = withDefaults(defineProps(), { checkbox: false, childrenColumnName: "children", + cellStyle: "", + cellClassName: "" }); const tableSelectedKeys: WritableComputedRef = computed({ @@ -75,11 +82,41 @@ const handleExpand = () => { isExpand.value = !isExpand.value; }; +const renderCellStyle = (row: any, column: any, rowIndex: number, columnIndex: number) => { + if(typeof props.cellStyle === 'string') { + return props.cellStyle; + } + return props.cellStyle(row, column, rowIndex, columnIndex); +} + +const renderCellClassName = (row: any, column: any, rowIndex: number, columnIndex: number) => { + if(typeof props.cellClassName === 'string') { + return props.cellClassName; + } + return props.cellClassName(row, column, rowIndex, columnIndex); +} + +const renderRowStyle = (data: any, index: number) => { + if(typeof props.rowStyle === 'string') { + return props.rowStyle; + } + return props.rowStyle(data, index); +} + +const renderRowClassName = (data: any, index: number) => { + if(typeof props.rowClassName === 'string') { + return props.rowClassName; + } + return props.rowClassName(data, index); +} + const childrenIndentSize = props.currentIndentSize + props.indentSize;