Skip to content

Commit

Permalink
fix(react-grid): handle column count decrease in virtual table (#2464)
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyLahtak authored Oct 21, 2019
1 parent 0cf0cd7 commit 2c21e30
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/dx-grid-core/src/types/virtual-table.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type GetSpanBoundaryFn = PureComputed<

/** @internal */
export type CollapseBoundariesFn = PureComputed<
[number, VisibleBoundary[], ReadonlyArray<VisibleBoundary>[], number],
[number, VisibleBoundary[], ReadonlyArray<VisibleBoundary>[]],
VisibleBoundary[]
>;

Expand Down
15 changes: 15 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 @@ -200,6 +200,21 @@ describe('VirtualTableLayout utils', () => {
.toEqual([[1, 5]]);
});

it('should nullify start of interval if that greater than end', () => {
const items = [
{ colSpan: 1 }, // 0
{ colSpan: 2 }, // 1, 2
{ colSpan: 1 }, // 3
{ colSpan: 1 }, // 4
{ colSpan: 1 }, // 5
{ colSpan: 1 }, // 6
{ colSpan: 1 }, // 7
];

expect(getSpanBoundary(items, [[5, 4]], item => item.colSpan))
.toEqual([[0, 4]]);
});

it('should work with multiple visible boundaries in a simple case', () => {
const items = [
{ colSpan: 1 }, // 0
Expand Down
5 changes: 2 additions & 3 deletions packages/dx-grid-core/src/utils/virtual-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export const getSpanBoundary: GetSpanBoundaryFn = (
items, visibleBoundaries, getItemSpan,
) => visibleBoundaries
.map((visibleBoundary) => {
let [start] = visibleBoundary;
const endIndex = Math.min(visibleBoundary[1], items.length - 1);
let end = endIndex;
let start = visibleBoundary[0] <= end ? visibleBoundary[0] : 0;

for (let index = 0; index <= endIndex; index += 1) {
const span = getItemSpan(items[index]);
Expand Down Expand Up @@ -290,10 +290,9 @@ export const getCollapsedGrid: GetCollapsedGridFn = ({
columns.length,
columnsVisibleBoundary,
rowSpanBoundaries,
0,
);

const rowBoundaries = collapseBoundaries(totalRowCount!, [boundaries], [], offset);
const rowBoundaries = collapseBoundaries(totalRowCount!, [boundaries], []);

return {
columns: getCollapsedColumns(
Expand Down

0 comments on commit 2c21e30

Please sign in to comment.