Skip to content

Commit

Permalink
fix(react-grid): consider fixed columns when columns are virtualized (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ushkal authored May 15, 2019
1 parent 01c4331 commit f13c525
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/dx-grid-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export { getGroupCellTargetIndex } from './utils/group-panel';
export {
getCollapsedGrid,
getCollapsedGrids,
getColumnsVisibleBoundary,
getColumnBoundaries,
getRowsVisibleBoundary,
getColumnsRenderBoundary,
getRowsRenderBoundary,
Expand Down
38 changes: 38 additions & 0 deletions packages/dx-grid-core/src/utils/virtual-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TABLE_STUB_TYPE,
getColumnWidthGetter,
getRenderBoundary,
getColumnBoundaries,
} from './virtual-table';

describe('VirtualTableLayout utils', () => {
Expand Down Expand Up @@ -57,6 +58,43 @@ describe('VirtualTableLayout utils', () => {
});
});

describe('#getColumnBoundaries', () => {
it('should return correct boundaries in simple case', () => {
const columns = [
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
];

expect(getColumnBoundaries(columns, 90, 100, col => col.size))
.toEqual([[1, 5]]);
});

it('should take fixed columns into account', () => {
const columns = [
{ size: 40, fixed: 'left' },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40 },
{ size: 40, fixed: 'right' },
];

expect(getColumnBoundaries(columns, 120, 80, col => col.size))
.toEqual([
[2, 5],
[0, 0],
[7, 7],
]);
});
});

describe('#getRenderBoundary', () => {
it('should correctly add overscan in simple case', () => {
expect(getRenderBoundary(20, [5, 10], 3)).toEqual([2, 13]);
Expand Down
20 changes: 9 additions & 11 deletions packages/dx-grid-core/src/utils/virtual-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ export const getRenderBoundary: GetRenderBoundaryFn = (itemsCount, visibleBounda
return [start, end];
};

export const getColumnsVisibleBoundary: PureComputed<
export const getColumnBoundaries: PureComputed<
[TableColumn[], number, number, GetColumnWidthFn], VisibleBoundary[]
> = (columns, left, width, getColumnWidth) => (
getVisibleBoundaryWithFixed(
getVisibleBoundary(columns, left, width, getColumnWidth, 0),
getColumnsRenderBoundary(
columns.length,
getVisibleBoundary(columns, left, width, getColumnWidth, 0),
),
columns,
)
);
Expand Down Expand Up @@ -354,14 +357,9 @@ export const getCollapsedGrids: GetCollapsedGridsFn = ({
tableRow: any, tableColumn: any,
) => getCellColSpan!({ tableRow, tableColumn, tableColumns: columns });

const visibleColumnBoundaries = [
getColumnsRenderBoundary(
columns.length,
getColumnsVisibleBoundary(
columns, viewportLeft, containerWidth, getColumnWidth,
)[0],
),
];
const columnBoundaries = getColumnBoundaries(
columns, viewportLeft, containerWidth, getColumnWidth,
);
const getCollapsedGridBlock: PureComputed<
[any[], any[]?, number?, number?], CollapsedGrid
> = (
Expand All @@ -370,7 +368,7 @@ export const getCollapsedGrids: GetCollapsedGridsFn = ({
rows,
columns,
rowsVisibleBoundary,
columnsVisibleBoundary: visibleColumnBoundaries,
columnsVisibleBoundary: columnBoundaries,
getColumnWidth,
getRowHeight,
getColSpan,
Expand Down

0 comments on commit f13c525

Please sign in to comment.