Skip to content

Commit

Permalink
feat: 明细表的 getCellData 可获取单行数据 (#1482)
Browse files Browse the repository at this point in the history
* chore: playground 添加链接跳转操作

* feat: 明细表的 getCellData 可获取单行数据

* test: 明细表的 getCellData 可获取单行数据
  • Loading branch information
stone-lyl authored Jun 23, 2022
1 parent c23e105 commit c3e1662
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/s2-core/__tests__/unit/data-set/table-data-set-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ describe('Table Mode Dataset Test', () => {

describe('test for query data', () => {
test('getCellData function', () => {
expect(
dataSet.getCellData({
query: { rowIndex: 0 },
}),
).toEqual({
city: '杭州市',
number: 7789,
province: '浙江省',
sub_type: '桌子',
type: '家具',
});

expect(
dataSet.getCellData({
query: {
Expand Down
8 changes: 7 additions & 1 deletion packages/s2-core/src/data-set/table-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ export class TableDataSet extends BaseDataSet {
if (this.displayData.length === 0 && query.rowIndex === 0) {
return;
}
return this.displayData[query.rowIndex][query.col];

const rowData = this.displayData[query.rowIndex];

if (!('col' in query)) {
return rowData;
}
return rowData[query.col];
}

public getMultiData(query: DataType, isTotals?: boolean): DataType[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class DataCellClick extends BaseEvent implements BaseEventImplement {
const { valueField: key, data: record } = cellData;
this.spreadsheet.emit(S2Event.GLOBAL_LINK_FIELD_JUMP, {
key,
record,
record: Object.assign({ rowIndex: cellData.rowIndex }, record),
});
}
}
Expand Down
21 changes: 21 additions & 0 deletions packages/s2-react/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function MainLayout() {
});
const [themeColor, setThemeColor] = React.useState<string>('#FFF');
const [showCustomTooltip, setShowCustomTooltip] = React.useState(false);
const [showJumpLink, setShowJumpLink] = React.useState(false);
const [adaptive, setAdaptive] = React.useState<Adaptive>(false);
const [options, setOptions] =
React.useState<Partial<S2Options<React.ReactNode>>>(defaultOptions);
Expand Down Expand Up @@ -266,6 +267,13 @@ function MainLayout() {
S2Event.DATA_CELL_TREND_ICON_CLICK,
logHandler('趋势图点击'),
);
s2Ref.current?.on(S2Event.GLOBAL_LINK_FIELD_JUMP, (data) => {
logHandler('🔗链接跳转 data:')(data);

window.open(
'https://s2.antv.vision/en/docs/manual/advanced/interaction/link-jump#%E6%A0%87%E8%AE%B0%E9%93%BE%E6%8E%A5%E5%AD%97%E6%AE%B5',
);
});
}, [sheetType]);

useUpdateEffect(() => {
Expand Down Expand Up @@ -772,6 +780,19 @@ function MainLayout() {
checked={showCustomTooltip}
onChange={setShowCustomTooltip}
/>
<Switch
checkedChildren="打开链接跳转"
unCheckedChildren="无链接跳转"
checked={showJumpLink}
onChange={(checked) => {
setShowJumpLink(checked);
updateOptions({
interaction: {
linkFields: checked ? ['province', 'city'] : [],
},
});
}}
/>
</Space>
</Collapse.Panel>
<Collapse.Panel header="交互配置" key="interaction">
Expand Down

0 comments on commit c3e1662

Please sign in to comment.