Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 暴露afterRealCellRender,这样能够更灵活的使用datacell #1970

Merged
merged 1 commit into from
Dec 9, 2022
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
13 changes: 13 additions & 0 deletions packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,19 @@ describe('PivotSheet Tests', () => {
expect(afterRender).toHaveBeenCalledTimes(1);
});

test('should emit after real dataCell render', () => {
const afterRealDataCellRender = jest.fn();
const sheet = new PivotSheet(container, dataCfg, s2Options);

sheet.on(
S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER,
afterRealDataCellRender,
);
sheet.render();

expect(afterRealDataCellRender).toHaveBeenCalledTimes(1);
});

test('should updatePagination', () => {
s2.updatePagination({
current: 2,
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/common/constant/events/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export enum S2Event {
LAYOUT_PAGINATION = 'layout:pagination',
LAYOUT_COLLAPSE_ROWS = 'layout:collapsed-rows',
LAYOUT_AFTER_COLLAPSE_ROWS = 'layout:after-collapsed-rows',
LAYOUT_AFTER_REAL_DATA_CELL_RENDER = 'layout:after-real-data-cell-render',
LAYOUT_TREE_ROWS_COLLAPSE_ALL = 'layout:toggle-collapse-all',
LAYOUT_COLS_EXPANDED = 'layout:table-col-expanded',
LAYOUT_COLS_HIDDEN = 'layout:table-col-hidden',
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-core/src/common/interface/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Event as CanvasEvent } from '@antv/g-canvas';
import type { SpreadSheet } from '../../sheet-type';
import type { DataCell } from '../../cell/data-cell';
import type { RowCell } from '../../cell/row-cell';
import type { ColCell } from '../../cell/col-cell';
Expand Down Expand Up @@ -145,6 +146,11 @@ export interface EmitterType {
current: number;
}) => void;
[S2Event.LAYOUT_AFTER_HEADER_LAYOUT]: (data: LayoutResult) => void;
[S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER]: (options: {
add: [number, number][];
remove: [number, number][];
spreadsheet: SpreadSheet;
}) => void;
/** @deprecated 请使用 S2Event.GLOBAL_SCROLL 代替 */
[S2Event.LAYOUT_CELL_SCROLL]: (position: CellScrollPosition) => void;
[S2Event.LAYOUT_COLS_EXPANDED]: (expandedNode: Node) => void;
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,11 @@ export abstract class BaseFacet {
);
});
this.preCellIndexes = indexes;
this.spreadsheet.emit(S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER, {
add,
remove,
spreadsheet: this.spreadsheet,
});
};

protected init() {
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-react/src/hooks/useEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ export function useEvents(props: SheetComponentsProps, s2: SpreadSheet) {
useS2Event(S2Event.GLOBAL_LINK_FIELD_JUMP, props.onLinkFieldJump, s2);
useS2Event(S2Event.GLOBAL_SCROLL, props.onScroll, s2);
// ============== Auto 自动生成的 ================
useS2Event(
S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER,
props.onLayoutAfterRealDataCellRender,
s2,
);
useS2Event(
S2Event.ROW_CELL_BRUSH_SELECTION,
props.onRowCellBrushSelection,
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-shared/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ export interface BaseSheetComponentProps<
onScroll?: (position: CellScrollPosition) => void;

// ============== Auto 自动生成的 ================
onLayoutAfterRealDataCellRender?: (options: {
add: [number, number][];
remove: [number, number][];
spreadsheet: SpreadSheet;
}) => void;
onRowCellBrushSelection?: (event: GEvent) => void;
onColCellBrushSelection?: (event: GEvent) => void;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-vue/src/hooks/useEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ export const useEvents = (
useS2Event(s2Ref, emit, S2Event.GLOBAL_SCROLL, 'scroll');

// ============== Auto 自动生成的 ================
useS2Event(
s2Ref,
emit,
S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER,
'layoutAfterRealDataCellRender',
);
useS2Event(
s2Ref,
emit,
Expand Down
1 change: 1 addition & 0 deletions packages/s2-vue/src/utils/initPropAndEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const initBaseSheetEmits = () => {
'scroll',
'hover',
// ============== Auto 自动生成的 ================
'layoutAfterRealDataCellRender',
'rowCellBrushSelection',
'colCellBrushSelection',
];
Expand Down
1 change: 1 addition & 0 deletions s2-site/docs/api/general/S2Event.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ s2.on(S2Event.ROW_CELL_CLICK, (event) => {
| 名称 | 事件名 | 描述 |
| ----------------------- | --------------------------------- | ------------------------------------------ |
| 表头布局完成 | `S2Event.LAYOUT_AFTER_HEADER_LAYOUT` | 行头和列头布局完成后触发 |
| 数值单元格布局完成 | `S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER` | 当前可视范围数值单元格渲染完成后触发 |
| 单元格虚拟滚动 | `S2Event.LAYOUT_CELL_SCROLL` | 已废弃,请使用 `S2Event.GLOBAL_SCROLL` 替代 |
| 分页 | `S2Event.LAYOUT_PAGINATION` | 分页事件 |
| 收起行头 | `S2Event.LAYOUT_COLLAPSE_ROWS` | 树状模式下收起行头的事件回调 |
Expand Down