Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/demo-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const initSchema: DripTableSchema<CustomColumnSchema, SubtableDataSourceK
],
},
pagination: {
sticky: true,
border: true,
simple: false,
pageSize: 20,
Expand Down
3 changes: 1 addition & 2 deletions docs/drip-table/demo/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DripTable, { DripTableFilters, DripTableInstance } from 'drip-table';
import { JsonEditor } from 'jsoneditor-react';
import React from 'react';

import { initSchema, mockData, SampleRecordType, SubtableDataSourceKey } from '../../demo-data';
import { initSchema, mockData, SampleRecordType } from '../../demo-data';
import { CustomColumnSchema, CustomComponentEvent, CustomComponents } from './custom-components';

import styles from './demo.module.less';
Expand Down Expand Up @@ -110,7 +110,6 @@ function Demo() {
CustomColumnSchema: CustomColumnSchema;
CustomComponentEvent: CustomComponentEvent;
CustomComponentExtraData: never;
SubtableDataSourceKey: SubtableDataSourceKey;
}>
ref={dripTable}
schema={schema}
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -35,9 +37,9 @@ function Indicator() {
}

const Spin = React.memo(({ ...props }: SpinProps) => (
<div className={`${prefixCls}-nested-loading`}>
<div className={classNames(`${prefixCls}-nested-loading`, props.className)}>
{ props.spinning && <Indicator /> }
<div className={classNames(`${prefixCls}-container`, { [`${prefixCls}-blur`]: props.spinning })}>
<div className={classNames(`${prefixCls}-container`, props.innerClassName, { [`${prefixCls}-blur`]: props.spinning })}>
{ props.tip }
{ props.children }
</div>
Expand Down
10 changes: 10 additions & 0 deletions packages/drip-table/src/layouts/index.less
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 6 additions & 2 deletions packages/drip-table/src/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -136,9 +138,11 @@ function DripTableLayout<

return (
<ErrorBoundary>
<Spin spinning={tableProps.loading}>
<Spin spinning={tableProps.loading} className={tableProps.spinClassName} innerClassName={tableProps.spinInnerClassName}>
<div
className={classnames(tableProps.className, tableProps.schema.className)}
className={classnames(tableProps.className, tableProps.schema.className, {
'jfe-drip-table-layout-table-sticky-container': tableProps.schema.pagination && tableProps.schema.pagination.sticky,
})}
style={Object.assign({}, tableProps.style, tableProps.schema.style, themeStyle)}
>
{ layoutNode }
Expand Down
90 changes: 53 additions & 37 deletions packages/drip-table/src/layouts/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,37 +180,37 @@ const hookColumRender = <
<React.Fragment>
{ render?.(d, row, index) }
{
columnSchema && ('sorter' in columnSchema || columnSchema.style || columnSchema.hoverStyle || columnSchema.rowHoverStyle || columnSchema.columnHoverStyle)
? (
<div
style={{ display: 'none' }}
ref={(el) => {
const tdEl = el?.parentElement;
if (tdEl) {
const context = { props: { record: row.record, recordIndex: row.index, ext: extraProps.ext } };
const parseStyleSchema = (style: string | Record<string, string> | 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)
? (
<div
style={{ display: 'none' }}
ref={(el) => {
const tdEl = el?.parentElement;
if (tdEl) {
const context = { props: { record: row.record, recordIndex: row.index, ext: extraProps.ext } };
const parseStyleSchema = (style: string | Record<string, string> | 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
}
</React.Fragment>
);
};
Expand Down Expand Up @@ -1422,7 +1422,9 @@ function TableLayout<
</Slot>
)
: (
<span className={`${prefixCls}-row-slot__error`}>{ `自定义插槽组件渲染函数 tableProps.slots['${slotType}'] 不存在` }</span>
<span className={`${prefixCls}-row-slot__error`}>
{ `自定义插槽组件渲染函数 tableProps.slots['${slotType}'] 不存在` }
</span>
);
}
return render?.(o, row, index);
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -1901,9 +1903,8 @@ function TableLayout<
[tableProps.emptyText, tableProps.schema.emptyText],
);

return (
const renderTableLayout = (
<React.Fragment>
{ paginationPosition === 'top' ? renderPagination : void 0 }
{ props.header }
<ResizeObserver onResize={rcTableOnResize}>
<div className={`${prefixCls}-resize-observer`}>
Expand Down Expand Up @@ -1968,9 +1969,24 @@ function TableLayout<
</div>
</ResizeObserver>
{ props.footer }
{ paginationPosition === 'bottom' ? renderPagination : void 0 }
</React.Fragment>
);

return tableProps.schema.pagination && tableProps.schema.pagination?.sticky
? (
<React.Fragment>
{ paginationPosition === 'top' ? renderPagination : void 0 }
<div>{ renderTableLayout }</div>
{ paginationPosition === 'bottom' ? renderPagination : void 0 }
</React.Fragment>
)
: (
<React.Fragment>
{ paginationPosition === 'top' ? renderPagination : void 0 }
{ renderTableLayout }
{ paginationPosition === 'bottom' ? renderPagination : void 0 }
</React.Fragment>
);
}

export default TableLayout;
3 changes: 3 additions & 0 deletions packages/drip-table/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export interface DripTableSchema<
* 是否展示分页以及配置
*/
pagination?: false | {
sticky?: boolean;
border?: boolean;
simple?: boolean;
size?: 'small' | 'default';
Expand Down Expand Up @@ -561,6 +562,8 @@ export interface DripTableProps<
* 自定义样式表
*/
style?: React.CSSProperties;
spinClassName?: string;
spinInnerClassName?: string;
/**
* 表单 Schema
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/drip-table/src/utils/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const getDripTablePropsAjvSchema = (options?: AjvOptions) => {
{
type: 'object',
properties: {
sticky: { type: 'boolean' },
border: { type: 'boolean' },
simple: { type: 'boolean' },
size: { enum: ['small', 'default'] },
Expand Down Expand Up @@ -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: {},
Expand Down