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

fix: #696 #700

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 240 files
6 changes: 2 additions & 4 deletions src/components/header/revogr-header.tsx
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import keyBy from 'lodash/keyBy';
import { HEADER_ACTUAL_ROW_CLASS, HEADER_ROW_CLASS } from '../../utils/consts';
import { Groups } from '@store';
import HeaderRenderer, { HeaderRenderProps } from './header-renderer';
import ColumnGroupsRenderer from '../../plugins/groupingColumn/columnGroupsRenderer';
import { ColumnGroupsRenderer } from '../../plugins/groupingColumn/columnGroupsRenderer';
import { ResizeProps } from './resizable.directive';
import {
ColumnRegular,
@@ -172,7 +172,6 @@ export class RevogrHeaderComponent {
const cols = this.viewportCol.get('items');
const range = this.selectionStore?.get('range');
const cells: VNode[] = [];
const visibleProps: { [prop: string]: number } = {};

// render header columns
for (let rgCol of cols) {
@@ -198,16 +197,15 @@ export class RevogrHeaderComponent {
continue;
}
cells.push(<HeaderRenderer {...event.detail} />);
visibleProps[colData?.prop] = rgCol.itemIndex;
}

return [
<div class="group-rgRow">
<ColumnGroupsRenderer
canResize={this.canResize}
active={this.resizeHandler}
visibleProps={visibleProps}
providers={this.providers}
cols={cols}
groups={this.groups}
dimensionCol={this.dimensionCol.state}
depth={this.groupingDepth}
37 changes: 21 additions & 16 deletions src/plugins/groupingColumn/columnGroupsRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
import { h } from '@stencil/core';
import findIndex from 'lodash/findIndex';
import { Group, getItemByIndex } from '@store';
import { DimensionSettingsState, Providers, DimensionCols } from '@type';
import { DimensionSettingsState, Providers, DimensionCols, PositionItem } from '@type';
import { HEADER_ROW_CLASS } from '../../utils/consts';
import GroupHeaderRenderer from './headerGroupRenderer';
import { GroupHeaderRenderer } from './headerGroupRenderer';
import { ResizeProps } from '../../components/header/resizable.directive';

type Props<T> = {
visibleProps: { [prop: string]: number };
groups: Record<number, Group[]>;
dimensionCol: Pick<DimensionSettingsState, 'indexes' | 'originItemSize' | 'indexToItem'>;
cols: PositionItem[];
depth: number;
canResize: boolean;
providers: Providers<T>;
additionalData: any;
onResize(changedX: number, startIndex: number, endIndex: number): void;
} & Partial<Pick<ResizeProps, 'active'>>;

const ColumnGroupsRenderer = ({
additionalData, providers, depth, groups, visibleProps, dimensionCol, canResize, active, onResize
export const ColumnGroupsRenderer = ({
additionalData, providers, depth, groups, dimensionCol, cols, canResize, active, onResize
}: Props<DimensionCols | 'rowHeaders'>): ReturnType<typeof h>[] => {
// render group columns
const groupRow: ReturnType<typeof h>[] = [];
const visibleIndexes = cols.map(col => col.itemIndex);

for (let i = 0; i < depth; i++) {
let groupStartIndex = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work, grouping not always start from 0 index, it can start from anywhere hence it's a flat group

if (groups[i]) {
for (let group of groups[i]) {
// if group in visible range
// find first visible group prop in visible columns range
const indexFirstVisibleCol: number | undefined = findIndex(group.ids, id => typeof visibleProps[id] === 'number');
if (indexFirstVisibleCol > -1) {
const colVisibleIndex = visibleProps[group.ids[indexFirstVisibleCol]]; // get column index
const groupStartIndex = colVisibleIndex - indexFirstVisibleCol; // first column index in group
const groupEndIndex = groupStartIndex + group.ids.length - 1; // last column index in group
// Calculate group boundaries based on array positions
const groupEndIndex = groupStartIndex + group.ids.length - 1;

// Check if any visible column is within this group's range
const isVisible = visibleIndexes.some(index =>
index >= groupStartIndex && index <= groupEndIndex
);

// coordinates
if (isVisible) {
// Get actual visible boundaries
const groupStart = getItemByIndex(dimensionCol, groupStartIndex).start;
const groupEnd = getItemByIndex(dimensionCol, groupEndIndex).end;

groupRow.push(
<GroupHeaderRenderer
providers={providers}
@@ -49,11 +53,12 @@ const ColumnGroupsRenderer = ({
/>,
);
}

// Move start index for next group
groupStartIndex = groupEndIndex + 1;
}
}
groupRow.push(<div class={`${HEADER_ROW_CLASS} group`} />);
}
return groupRow;
};

export default ColumnGroupsRenderer;
4 changes: 1 addition & 3 deletions src/plugins/groupingColumn/headerGroupRenderer.tsx
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ type Props = {
onResize?(e: ResizeEvent): void;
} & Partial<Pick<ResizeProps, 'active'>>;

const GroupHeaderRenderer = (p: Props): ReturnType<typeof h> => {
export const GroupHeaderRenderer = (p: Props): ReturnType<typeof h> => {
const groupProps: CellProps & Partial<ResizeProps> = {
canResize: p.canResize,
minWidth: p.group.ids.length * MIN_COL_SIZE,
@@ -44,5 +44,3 @@ const GroupHeaderRenderer = (p: Props): ReturnType<typeof h> => {
/>
);
};

export default GroupHeaderRenderer;