Skip to content

Commit

Permalink
feat: 暴露afterRealCellRender,这样能够更灵活的使用datacell
Browse files Browse the repository at this point in the history
  • Loading branch information
杨骥 committed Dec 7, 2022
1 parent 9250487 commit ccfd146
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/s2-core/__tests__/spreadsheet/spread-sheet-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as mockDataConfig from 'tests/data/simple-data.json';
import { getContainer, sleep } from 'tests/util/helpers';
import { pick } from 'lodash';
import { after, pick } from 'lodash';
import { PivotSheet, TableSheet } from '@/sheet-type';
import {
DEFAULT_OPTIONS,
Expand Down Expand Up @@ -240,13 +240,18 @@ describe('SpreadSheet Tests', () => {

const beforeRender = jest.fn();
const afterRender = jest.fn();
const afterRealDataCellRender = jest.fn();

const clearDrillDownDataSpy = jest
.spyOn(s2, 'clearDrillDownData')
.mockImplementationOnce(() => {});

s2.on(S2Event.LAYOUT_BEFORE_RENDER, beforeRender);
s2.on(S2Event.LAYOUT_AFTER_RENDER, afterRender);
s2.on(
S2Event.LAYOUT_AFTER_REAL_DATA_CELL_RENDER,
afterRealDataCellRender,
);
s2.destroy();

Array.from({ length: 10 }).forEach(() => {
Expand All @@ -255,6 +260,7 @@ describe('SpreadSheet Tests', () => {

expect(beforeRender).toHaveBeenCalledTimes(0);
expect(afterRender).toHaveBeenCalledTimes(0);
expect(afterRealDataCellRender).toHaveBeenCalledTimes(0);
expect(clearDrillDownDataSpy).toHaveBeenCalledTimes(0);
},
);
Expand Down
4 changes: 1 addition & 3 deletions packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ export class DataCell extends BaseCell<ViewMeta> {
this.drawTextShape();
this.drawConditionIconShapes();
}
if (this.meta.isFrozenCorner) {
this.drawBorderShape();
}
this.drawBorderShape();
this.update();
}

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
1 change: 1 addition & 0 deletions packages/s2-core/src/common/interface/s2Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface S2Options<T = TooltipContentType, P = Pagination>
S2PivotSheetOptions {
// custom data set
dataSet?: (spreadsheet: SpreadSheet) => BaseDataSet;
afterRealCellRender?: (spreadsheet: SpreadSheet) => void;
}

export interface S2RenderOptions {
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
1 change: 1 addition & 0 deletions packages/s2-shared/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export interface BaseSheetComponentProps<
onScroll?: (position: CellScrollPosition) => void;

// ============== Auto 自动生成的 ================
onLayoutAfterRealDataCellRender?: (event: GEvent) => 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` | 行头和列头布局完成后触发 |
| 单元格布局完成 | `LAYOUT_AFTER_REAL_DATA_CELL_RENDER` | 单元格渲染完成后触发 |
| 单元格虚拟滚动 | `S2Event.LAYOUT_CELL_SCROLL` | 已废弃,请使用 `S2Event.GLOBAL_SCROLL` 替代 |
| 分页 | `S2Event.LAYOUT_PAGINATION` | 分页事件 |
| 收起行头 | `S2Event.LAYOUT_COLLAPSE_ROWS` | 树状模式下收起行头的事件回调 |
Expand Down

0 comments on commit ccfd146

Please sign in to comment.