From 05060ed6ece5f0d9259b5da2fbc24f043c5519f6 Mon Sep 17 00:00:00 2001 From: helloqian12138 Date: Thu, 6 Feb 2025 11:25:13 +0800 Subject: [PATCH 1/2] feat: table support pagination sticky style --- docs/demo-data.ts | 1 + docs/drip-table/demo/demo.tsx | 3 +- .../react-components/spin/index.tsx | 6 +- packages/drip-table/src/layouts/index.less | 10 +++ packages/drip-table/src/layouts/index.tsx | 8 +- .../drip-table/src/layouts/table/index.tsx | 90 +++++++++++-------- packages/drip-table/src/types/index.ts | 3 + packages/drip-table/src/utils/ajv.ts | 3 + 8 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 packages/drip-table/src/layouts/index.less diff --git a/docs/demo-data.ts b/docs/demo-data.ts index cac31e99c..698cd4446 100644 --- a/docs/demo-data.ts +++ b/docs/demo-data.ts @@ -63,6 +63,7 @@ export const initSchema: DripTableSchema ref={dripTable} schema={schema} diff --git a/packages/drip-table/src/components/react-components/spin/index.tsx b/packages/drip-table/src/components/react-components/spin/index.tsx index c83a09217..718163be2 100644 --- a/packages/drip-table/src/components/react-components/spin/index.tsx +++ b/packages/drip-table/src/components/react-components/spin/index.tsx @@ -15,6 +15,8 @@ export interface SpinProps { children?: React.ReactNode; spinning?: boolean; tip?: string; + className?: string; + innerClassName?: string; } const prefixCls = 'jfe-drip-table-rc-spin'; @@ -35,9 +37,9 @@ function Indicator() { } const Spin = React.memo(({ ...props }: SpinProps) => ( -
+
{ props.spinning && } -
+
{ props.tip } { props.children }
diff --git a/packages/drip-table/src/layouts/index.less b/packages/drip-table/src/layouts/index.less new file mode 100644 index 000000000..84fab55c6 --- /dev/null +++ b/packages/drip-table/src/layouts/index.less @@ -0,0 +1,10 @@ +@import url("@@drip-table-src/styles/theme/default.less"); + +@prefixCls: jfe-drip-table-layout-table; + +.@{prefixCls}-sticky-container { + display: flex; + flex-direction: column; + justify-content: space-between; + flex: 1; +} diff --git a/packages/drip-table/src/layouts/index.tsx b/packages/drip-table/src/layouts/index.tsx index 360d64393..c48140d87 100755 --- a/packages/drip-table/src/layouts/index.tsx +++ b/packages/drip-table/src/layouts/index.tsx @@ -6,6 +6,8 @@ * @copyright: Copyright (c) 2021 JD Network Technology Co., Ltd. */ +import './index.less'; + import classnames from 'classnames'; import React, { useEffect } from 'react'; @@ -136,9 +138,11 @@ function DripTableLayout< return ( - +
{ layoutNode } diff --git a/packages/drip-table/src/layouts/table/index.tsx b/packages/drip-table/src/layouts/table/index.tsx index 603e68430..1a94a5a3d 100644 --- a/packages/drip-table/src/layouts/table/index.tsx +++ b/packages/drip-table/src/layouts/table/index.tsx @@ -180,37 +180,37 @@ const hookColumRender = < { render?.(d, row, index) } { - columnSchema && ('sorter' in columnSchema || columnSchema.style || columnSchema.hoverStyle || columnSchema.rowHoverStyle || columnSchema.columnHoverStyle) - ? ( -
{ - const tdEl = el?.parentElement; - if (tdEl) { - const context = { props: { record: row.record, recordIndex: row.index, ext: extraProps.ext } }; - const parseStyleSchema = (style: string | Record | undefined) => parseCSS(typeof style === 'string' ? safeExecute(style, context) : style); - tdEl.dataset.tableUuid = tableInfo.uuid; - tdEl.dataset.columnKey = columnSchema.key; - tdEl.dataset.rowKey = row.key; - tdEl.dataset.basicStyle = stringifyCSS(Object.assign( - { - 'text-align': columnSchema.align, - background: sorter?.key === columnSchema.key ? 'var(--drip-table-column-sorted-background-color, inherit)' : void 0, - }, - parseStyleSchema(columnSchema.style), - )); - tdEl.dataset.hoverStyle = stringifyCSS(parseStyleSchema(columnSchema.hoverStyle)); - tdEl.dataset.rowHoverStyle = stringifyCSS(parseStyleSchema(columnSchema.rowHoverStyle)); - tdEl.dataset.columnHoverStyle = stringifyCSS(parseStyleSchema(columnSchema.columnHoverStyle)); - tdEl.addEventListener('mouseenter', onCellMouseEnter); - tdEl.addEventListener('mouseleave', onCellMouseLeave); - updateCellElementStyle(tdEl, void 0, void 0); - } - }} - /> - ) - : null - } + columnSchema && ('sorter' in columnSchema || columnSchema.style || columnSchema.hoverStyle || columnSchema.rowHoverStyle || columnSchema.columnHoverStyle) + ? ( +
{ + const tdEl = el?.parentElement; + if (tdEl) { + const context = { props: { record: row.record, recordIndex: row.index, ext: extraProps.ext } }; + const parseStyleSchema = (style: string | Record | undefined) => parseCSS(typeof style === 'string' ? safeExecute(style, context) : style); + tdEl.dataset.tableUuid = tableInfo.uuid; + tdEl.dataset.columnKey = columnSchema.key; + tdEl.dataset.rowKey = row.key; + tdEl.dataset.basicStyle = stringifyCSS(Object.assign( + { + 'text-align': columnSchema.align, + background: sorter?.key === columnSchema.key ? 'var(--drip-table-column-sorted-background-color, inherit)' : void 0, + }, + parseStyleSchema(columnSchema.style), + )); + tdEl.dataset.hoverStyle = stringifyCSS(parseStyleSchema(columnSchema.hoverStyle)); + tdEl.dataset.rowHoverStyle = stringifyCSS(parseStyleSchema(columnSchema.rowHoverStyle)); + tdEl.dataset.columnHoverStyle = stringifyCSS(parseStyleSchema(columnSchema.columnHoverStyle)); + tdEl.addEventListener('mouseenter', onCellMouseEnter); + tdEl.addEventListener('mouseleave', onCellMouseLeave); + updateCellElementStyle(tdEl, void 0, void 0); + } + }} + /> + ) + : null + } ); }; @@ -1422,7 +1422,9 @@ function TableLayout< ) : ( - { `自定义插槽组件渲染函数 tableProps.slots['${slotType}'] 不存在` } + + { `自定义插槽组件渲染函数 tableProps.slots['${slotType}'] 不存在` } + ); } return render?.(o, row, index); @@ -1772,8 +1774,8 @@ function TableLayout< ...subtable ? tableProps.subtableProps.filter(sp => sp.subtableID === subtable.id) || [] : [], ...tableProps.subtableProps.filter( sp => sp.recordKeys - && sp.recordKeys.length === 1 - && sp.recordKeys[0] === row.record[rowKey], + && sp.recordKeys.length === 1 + && sp.recordKeys[0] === row.record[rowKey], ) || [], ].map(sp => sp.properties), ) @@ -1901,9 +1903,8 @@ function TableLayout< [tableProps.emptyText, tableProps.schema.emptyText], ); - return ( + const renderTableLayout = ( - { paginationPosition === 'top' ? renderPagination : void 0 } { props.header }
@@ -1968,9 +1969,24 @@ function TableLayout<
{ props.footer } - { paginationPosition === 'bottom' ? renderPagination : void 0 }
); + + return tableProps.schema.pagination && tableProps.schema.pagination?.sticky + ? ( + + { paginationPosition === 'top' ? renderPagination : void 0 } +
{ renderTableLayout }
+ { paginationPosition === 'bottom' ? renderPagination : void 0 } +
+ ) + : ( + + { paginationPosition === 'top' ? renderPagination : void 0 } + { renderTableLayout } + { paginationPosition === 'bottom' ? renderPagination : void 0 } + + ); } export default TableLayout; diff --git a/packages/drip-table/src/types/index.ts b/packages/drip-table/src/types/index.ts index fefdc66a6..f581a2b93 100644 --- a/packages/drip-table/src/types/index.ts +++ b/packages/drip-table/src/types/index.ts @@ -256,6 +256,7 @@ export interface DripTableSchema< * 是否展示分页以及配置 */ pagination?: false | { + sticky?: boolean; border?: boolean; simple?: boolean; size?: 'small' | 'default'; @@ -561,6 +562,8 @@ export interface DripTableProps< * 自定义样式表 */ style?: React.CSSProperties; + spinClassName?: string; + spinInnerClassName?: string; /** * 表单 Schema */ diff --git a/packages/drip-table/src/utils/ajv.ts b/packages/drip-table/src/utils/ajv.ts index 872ddd2d0..11d3f079a 100644 --- a/packages/drip-table/src/utils/ajv.ts +++ b/packages/drip-table/src/utils/ajv.ts @@ -275,6 +275,7 @@ const getDripTablePropsAjvSchema = (options?: AjvOptions) => { { type: 'object', properties: { + sticky: { type: 'boolean' }, border: { type: 'boolean' }, simple: { type: 'boolean' }, size: { enum: ['small', 'default'] }, @@ -435,6 +436,8 @@ const getDripTablePropsAjvSchema = (options?: AjvOptions) => { items: {}, }, className: { type: 'string' }, + spinClassName: { type: 'string' }, + spinInnerClassName: { type: 'string' }, style: DRIP_TABLE_CSS_SCHEMA, selectedRowKeys: {}, displayColumnKeys: {}, From 80b231674e6a0d535258b306348eb86805b992cc Mon Sep 17 00:00:00 2001 From: helloqian12138 Date: Thu, 6 Feb 2025 11:26:53 +0800 Subject: [PATCH 2/2] release: drip-table v3.2.2-alpha.1 --- packages/drip-table/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/drip-table/package.json b/packages/drip-table/package.json index 721f6ea86..cff7b471d 100755 --- a/packages/drip-table/package.json +++ b/packages/drip-table/package.json @@ -1,6 +1,6 @@ { "name": "drip-table", - "version": "3.2.1-alpha.12", + "version": "3.2.2-alpha.1", "description": "A tiny and powerful enterprise-class solution for building tables.", "main": "dist/index.min.js", "module": "lib/index.js",