Skip to content

Commit

Permalink
feat(dx-react-grid) remote virtual scrolling (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
ushkal authored Apr 22, 2019
1 parent 078a1f7 commit 43c967c
Show file tree
Hide file tree
Showing 64 changed files with 3,916 additions and 1,268 deletions.
21 changes: 20 additions & 1 deletion packages/dx-grid-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,26 @@ export { getGroupCellTargetIndex } from './utils/group-panel';

/** @internal */
export {
getCollapsedGrid, TABLE_STUB_TYPE, getColumnWidthGetter,
getCollapsedGrid,
getCollapsedGrids,
getColumnsVisibleBoundary,
getRowsVisibleBoundary,
getColumnsRenderBoundary,
getRowsRenderBoundary,
getColumnWidthGetter,
TABLE_STUB_TYPE,
} from './utils/virtual-table';

/** @internal */
export * from './plugins/virtual-table/computeds';
/** @internal */
export * from './plugins/virtual-table/helpers';

/** @internal */
export * from './plugins/virtual-table-state/computeds';
/** @internal */
export * from './plugins/virtual-table-state/utils';
/** @internal */
export * from './plugins/virtual-table-state/helpers';

export * from './types';
9 changes: 6 additions & 3 deletions packages/dx-grid-core/src/plugins/table/computeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ export const tableColumnsWithDataRows: PureComputed<[any[], GridColumnExtension[
};
});

export const tableRowsWithDataRows: PureComputed<[Row[], GetRowIdFn]> = (rows, getRowId) => (
!rows.length
export const tableRowsWithDataRows: PureComputed<[Row[], GetRowIdFn, number]> = (
rows, getRowId, isRemoteRowsLoading,
) => (
!rows.length && !isRemoteRowsLoading
? [{ key: TABLE_NODATA_TYPE.toString(), type: TABLE_NODATA_TYPE }]
: rows.map((row) => {
: rows.map((row, dataIndex) => {
const rowId = getRowId(row);
return {
row,
// dataIndex,
rowId,
type: TABLE_DATA_TYPE,
key: `${TABLE_DATA_TYPE.toString()}_${rowId}`,
Expand Down
4 changes: 4 additions & 0 deletions packages/dx-grid-core/src/plugins/table/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TABLE_DATA_TYPE, TABLE_NODATA_TYPE } from './constants';
import {
IsSpecificCellFn, IsSpecificRowFn, TableRow, TableColumn,
} from '../../types';
import { TABLE_STUB_TYPE } from '../../utils/virtual-table';

export const isDataTableCell: IsSpecificCellFn = (
tableRow, tableColumn,
Expand All @@ -14,3 +15,6 @@ export const isNoDataTableRow: IsSpecificRowFn = tableRow => tableRow.type === T
export const isNoDataTableCell: IsSpecificCellFn<TableColumn, TableColumn[]> = (
tableColumn, tableColumns,
) => tableColumns.indexOf(tableColumn as any) === 0;
export const isStubTableCell: IsSpecificRowFn = tableRow => (
tableRow.type === TABLE_STUB_TYPE
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { virtualRowsWithCache } from './computeds';
import { mergeRows } from './helpers';
import { createVirtualRows, createInterval } from './test-utils';

jest.mock('./helpers', () => ({
mergeRows: jest.fn(),
}));

describe('VirtualTableState computeds', () => {
describe('#virtualRowsWithCache', () => {
it('should call mergeRows with correct parameters', () => {
const rowsInterval = createInterval(20, 30);
const cacheInterval = createInterval(15, 25);
const { skip, rows } = createVirtualRows(rowsInterval);
const cache = createVirtualRows(cacheInterval);

virtualRowsWithCache(skip, rows, cache);

expect(mergeRows).toHaveBeenCalledWith(
{ start: 20, end: 30 },
{ start: 15, end: 25 },
rows,
cache.rows,
20,
15,
);
});
});
});
14 changes: 14 additions & 0 deletions packages/dx-grid-core/src/plugins/virtual-table-state/computeds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mergeRows } from './helpers';
import { intervalUtil } from './utils';
import { VirtualRowsWithCacheFn, PlainRowsFn, LoadedRowsStartFn } from '../../types';

export const virtualRowsWithCache: VirtualRowsWithCacheFn = (skip, rows, cache) => {
const rowsInterval = intervalUtil.getRowsInterval({ skip, rows });
const cacheInterval = intervalUtil.getRowsInterval(cache);

return mergeRows(rowsInterval, cacheInterval, rows, cache.rows, skip, cache.skip);
};

export const plainRows: PlainRowsFn = virtualRows => virtualRows.rows;

export const loadedRowsStart: LoadedRowsStartFn = virtualRows => virtualRows.skip;
Loading

0 comments on commit 43c967c

Please sign in to comment.