From 1e07d17b4eebe488055c991cb0036fae8db66ff4 Mon Sep 17 00:00:00 2001 From: ZeeshanTamboli Date: Sat, 31 Jul 2021 11:16:01 +0530 Subject: [PATCH 1/6] add scroll and scrollToIndexes API docs --- .../data-grid/grid-virtualization-api.json | 16 ++++++++++++++++ .../virtualization/VirtualizationApiNoSnap.js | 7 +++++++ .../data-grid/virtualization/virtualization.md | 4 ++++ 3 files changed, 27 insertions(+) create mode 100644 docs/pages/api-docs/data-grid/grid-virtualization-api.json create mode 100644 docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js diff --git a/docs/pages/api-docs/data-grid/grid-virtualization-api.json b/docs/pages/api-docs/data-grid/grid-virtualization-api.json new file mode 100644 index 000000000000..4cfb87cbb6d6 --- /dev/null +++ b/docs/pages/api-docs/data-grid/grid-virtualization-api.json @@ -0,0 +1,16 @@ +{ + "name": "GridVirtualizationApi", + "description": "The virtualization API interface that is available in the grid.", + "properties": [ + { + "name": "scroll", + "description": "Triggers the viewport to scroll to the given positions (in pixels).", + "type": "(params: Partial) => void" + }, + { + "name": "scrollToIndexes", + "description": "Triggers the viewport to scroll to the cell at indexes given by params. Returns true if the grid had to scroll to reach the target.", + "type": "(params: Optional) => boolean" + } + ] +} diff --git a/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js b/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js new file mode 100644 index 000000000000..9c2cac5d1623 --- /dev/null +++ b/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js @@ -0,0 +1,7 @@ +import React from 'react'; +import ApiDocs from 'docsx/src/modules/components/ApiDocs'; +import api from '../../../../../pages/api-docs/data-grid/grid-virtualization-api.json'; + +export default function VirtualizationApiNoSnap() { + return ; +} diff --git a/docs/src/pages/components/data-grid/virtualization/virtualization.md b/docs/src/pages/components/data-grid/virtualization/virtualization.md index 74a47a70d73a..293d6366515c 100644 --- a/docs/src/pages/components/data-grid/virtualization/virtualization.md +++ b/docs/src/pages/components/data-grid/virtualization/virtualization.md @@ -33,6 +33,10 @@ By default, 2 columns are rendered outside of the viewport. You can change this You can disable column virtualization by setting the column buffer to a higher number than the number of rendered columns, e.g. with `columnBuffer={columns.length}` or `columnBuffer={Number.MAX_SAFE_INTEGER}`. +## apiRef [](https://material-ui.com/store/items/material-ui-pro/) + +{{"demo": "pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js", "bg": "inline", "hideToolbar": true}} + ## API - [DataGrid](/api/data-grid/data-grid/) From 90d84e24546e221762d25183333c3172f8317893 Mon Sep 17 00:00:00 2001 From: ZeeshanTamboli Date: Sat, 31 Jul 2021 11:29:48 +0530 Subject: [PATCH 2/6] add getScrollPosition and updateViewport in api docs --- .../api-docs/data-grid/grid-virtualization-api.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/pages/api-docs/data-grid/grid-virtualization-api.json b/docs/pages/api-docs/data-grid/grid-virtualization-api.json index 4cfb87cbb6d6..ae16217e523b 100644 --- a/docs/pages/api-docs/data-grid/grid-virtualization-api.json +++ b/docs/pages/api-docs/data-grid/grid-virtualization-api.json @@ -11,6 +11,16 @@ "name": "scrollToIndexes", "description": "Triggers the viewport to scroll to the cell at indexes given by params. Returns true if the grid had to scroll to reach the target.", "type": "(params: Optional) => boolean" + }, + { + "name": "getScrollPosition", + "description": "Returns the current scroll position.", + "type": "() => GridScrollParams" + }, + { + "name": "updateViewport", + "description": "Refreshes the viewport cells according to the scroll positions.", + "type": "(forceRender?: boolean) => void" } ] } From c04fee68b8f5cbaf9d0f71f09b8536b71d6aa8e3 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 31 Jul 2021 16:59:14 +0200 Subject: [PATCH 3/6] make updateViewport private, it should not be needed so far --- docs/pages/api-docs/data-grid/grid-api.md | 1 - packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/api-docs/data-grid/grid-api.md b/docs/pages/api-docs/data-grid/grid-api.md index ffe014609fb2..e48fe29d5181 100644 --- a/docs/pages/api-docs/data-grid/grid-api.md +++ b/docs/pages/api-docs/data-grid/grid-api.md @@ -90,5 +90,4 @@ import { GridApi } from '@material-ui/x-grid'; | updateColumn | (col: GridColDef) => void | Updates the definition of a column. | | updateColumns | (cols: GridColDef[]) => void | Updates the definition of multiple columns at the same time. | | updateRows | (updates: GridRowModelUpdate<>[]) => void | Allows to updates, insert and delete rows in a single call. | -| updateViewport | (forceRender?: boolean) => void | Refreshes the viewport cells according to the scroll positions | | upsertFilter | (item: GridFilterItem) => void | Updates or inserts a GridFilterItem. | diff --git a/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts b/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts index 747de9e55f2d..cb3964dcb250 100644 --- a/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts +++ b/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts @@ -38,6 +38,7 @@ export interface GridVirtualizationApi { /** * Refreshes the viewport cells according to the scroll positions * @param {boolean} forceRender If `true`, forces a rerender. By default, it is `false`. + * @ignore - do not document. */ updateViewport: (forceRender?: boolean) => void; } From 655698d15475e70d2c7b5b2917210ddff4d54516 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 31 Jul 2021 17:02:45 +0200 Subject: [PATCH 4/6] absolute path --- .../src/pages/components/data-grid/export/CsvExportApiNoSnap.js | 2 +- .../src/pages/components/data-grid/filtering/FilterApiNoSnap.js | 2 +- .../pages/components/data-grid/selection/SelectionApiNoSnap.js | 2 +- .../data-grid/virtualization/VirtualizationApiNoSnap.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/pages/components/data-grid/export/CsvExportApiNoSnap.js b/docs/src/pages/components/data-grid/export/CsvExportApiNoSnap.js index ba500c3cd8d3..460ddbb135c0 100644 --- a/docs/src/pages/components/data-grid/export/CsvExportApiNoSnap.js +++ b/docs/src/pages/components/data-grid/export/CsvExportApiNoSnap.js @@ -1,6 +1,6 @@ import React from 'react'; import ApiDocs from 'docsx/src/modules/components/ApiDocs'; -import api from '../../../../../pages/api-docs/data-grid/grid-csv-export-api.json'; +import api from 'docsx/pages/api-docs/data-grid/grid-csv-export-api.json'; export default function CsvExportApiNoSnap() { return ; diff --git a/docs/src/pages/components/data-grid/filtering/FilterApiNoSnap.js b/docs/src/pages/components/data-grid/filtering/FilterApiNoSnap.js index 37c80fc99c7c..750540a49b57 100644 --- a/docs/src/pages/components/data-grid/filtering/FilterApiNoSnap.js +++ b/docs/src/pages/components/data-grid/filtering/FilterApiNoSnap.js @@ -1,6 +1,6 @@ import React from 'react'; import ApiDocs from 'docsx/src/modules/components/ApiDocs'; -import api from '../../../../../pages/api-docs/data-grid/grid-filter-api.json'; +import api from 'docsx/pages/api-docs/data-grid/grid-filter-api.json'; export default function FilterApiNoSnap() { return ; diff --git a/docs/src/pages/components/data-grid/selection/SelectionApiNoSnap.js b/docs/src/pages/components/data-grid/selection/SelectionApiNoSnap.js index e9b9614fe738..bd068f26f428 100644 --- a/docs/src/pages/components/data-grid/selection/SelectionApiNoSnap.js +++ b/docs/src/pages/components/data-grid/selection/SelectionApiNoSnap.js @@ -1,6 +1,6 @@ import React from 'react'; import ApiDocs from 'docsx/src/modules/components/ApiDocs'; -import api from '../../../../../pages/api-docs/data-grid/grid-selection-api.json'; +import api from 'docsx/pages/api-docs/data-grid/grid-selection-api.json'; export default function SelectionApiNoSnap() { return ; diff --git a/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js b/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js index 9c2cac5d1623..7a9274542a6e 100644 --- a/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js +++ b/docs/src/pages/components/data-grid/virtualization/VirtualizationApiNoSnap.js @@ -1,6 +1,6 @@ import React from 'react'; import ApiDocs from 'docsx/src/modules/components/ApiDocs'; -import api from '../../../../../pages/api-docs/data-grid/grid-virtualization-api.json'; +import api from 'docsx/pages/api-docs/data-grid/grid-virtualization-api.json'; export default function VirtualizationApiNoSnap() { return ; From e68653431187aaccb8d08c5338adc3e604df099e Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 31 Jul 2021 17:04:40 +0200 Subject: [PATCH 5/6] partial is enough --- docs/pages/api-docs/data-grid/grid-api.md | 2 +- .../grid/hooks/features/virtualization/useGridVirtualRows.ts | 4 ++-- .../grid/_modules_/grid/models/api/gridVirtualizationApi.ts | 3 +-- packages/grid/_modules_/grid/utils/utils.ts | 3 --- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/pages/api-docs/data-grid/grid-api.md b/docs/pages/api-docs/data-grid/grid-api.md index e48fe29d5181..97356bac0acb 100644 --- a/docs/pages/api-docs/data-grid/grid-api.md +++ b/docs/pages/api-docs/data-grid/grid-api.md @@ -59,7 +59,7 @@ import { GridApi } from '@material-ui/x-grid'; | publishEvent | (name: string, params?: any, event?: MuiEvent<MouseEvent \| UIEvent \| Event \| SyntheticEvent<Element, Event> \| KeyboardEvent \| ClipboardEvent \| ProgressEvent<EventTarget> \| ErrorEvent \| AnimationEvent \| InputEvent \| FocusEvent \| CompositionEvent \| DragEvent \| PointerEvent \| SecurityPolicyViolationEvent \| TouchEvent \| TransitionEvent \| WheelEvent>) => void | Emits an event. | | resize | () => void | Triggers a resize of the component and recalculation of width and height. | | scroll | (params: Partial<GridScrollParams>) => void | Triggers the viewport to scroll to the given positions (in pixels). | -| scrollToIndexes | (params: Optional<GridCellIndexCoordinates, rowIndex>) => boolean | Triggers the viewport to scroll to the cell at indexes given by `params`.
Returns `true` if the grid had to scroll to reach the target. | +| scrollToIndexes | (params: Partial<GridCellIndexCoordinates>) => boolean | Triggers the viewport to scroll to the cell at indexes given by `params`.
Returns `true` if the grid had to scroll to reach the target. | | selectRow | (id: GridRowId, isSelected?: boolean, allowMultiple?: boolean) => void | Change the selection state of a row. | | selectRows | (ids: GridRowId[], isSelected?: boolean, deselectOtherRows?: boolean) => void | Change the selection state of multiple rows. | | setCellFocus | (id: GridRowId, field: string) => void | Sets the focus to the cell at the given `id` and `field`. | diff --git a/packages/grid/_modules_/grid/hooks/features/virtualization/useGridVirtualRows.ts b/packages/grid/_modules_/grid/hooks/features/virtualization/useGridVirtualRows.ts index be31a3ad2b2b..d0a4da820d0a 100644 --- a/packages/grid/_modules_/grid/hooks/features/virtualization/useGridVirtualRows.ts +++ b/packages/grid/_modules_/grid/hooks/features/virtualization/useGridVirtualRows.ts @@ -5,7 +5,7 @@ import { GridVirtualizationApi } from '../../../models/api/gridVirtualizationApi import { GridCellIndexCoordinates } from '../../../models/gridCell'; import { GridScrollParams } from '../../../models/params/gridScrollParams'; import { GridRenderContextProps, GridRenderRowProps } from '../../../models/gridRenderContextProps'; -import { isDeepEqual, Optional } from '../../../utils/utils'; +import { isDeepEqual } from '../../../utils/utils'; import { useEnhancedEffect } from '../../../utils/material-ui-utils'; import { optionsSelector } from '../../utils/optionsSelector'; import { @@ -199,7 +199,7 @@ export const useGridVirtualRows = (apiRef: GridApiRef): void => { ); const scrollToIndexes = React.useCallback( - (params: Optional) => { + (params: Partial) => { if (totalRowCount === 0 || visibleColumns.length === 0) { return false; } diff --git a/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts b/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts index cb3964dcb250..aed299275f33 100644 --- a/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts +++ b/packages/grid/_modules_/grid/models/api/gridVirtualizationApi.ts @@ -2,7 +2,6 @@ import { GridCellIndexCoordinates } from '../gridCell'; import { GridContainerProps } from '../gridContainerProps'; import { GridScrollParams } from '../params/gridScrollParams'; import { GridRenderContextProps } from '../gridRenderContextProps'; -import { Optional } from '../../utils/utils'; /** * The virtualization API interface that is available in the grid [[apiRef]]. @@ -19,7 +18,7 @@ export interface GridVirtualizationApi { * @param {GridCellIndexCoordinates} params The indexes where the cell is. * @returns {boolean} Returns `true` if the index was outside of the viewport and the grid had to scroll to reach the target. */ - scrollToIndexes: (params: Optional) => boolean; + scrollToIndexes: (params: Partial) => boolean; /** * Get the current containerProps. * @ignore - do not document. diff --git a/packages/grid/_modules_/grid/utils/utils.ts b/packages/grid/_modules_/grid/utils/utils.ts index 7f8992f56fd9..5bd23648605e 100644 --- a/packages/grid/_modules_/grid/utils/utils.ts +++ b/packages/grid/_modules_/grid/utils/utils.ts @@ -63,9 +63,6 @@ export function localStorageAvailable() { } } -// Util to make specific interface properties optional -export type Optional = Pick, K> & Omit; - export function getDataGridUtilityClass(slot) { return generateUtilityClass(GRID_CSS_CLASS_PREFIX, slot); } From 8189978983f64cf6a24336fbc966bd291e177bde Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 31 Jul 2021 17:08:58 +0200 Subject: [PATCH 6/6] it's not done by hand --- .../data-grid/grid-virtualization-api.json | 21 +++++++------------ docs/scripts/buildApi.ts | 1 + 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/docs/pages/api-docs/data-grid/grid-virtualization-api.json b/docs/pages/api-docs/data-grid/grid-virtualization-api.json index ae16217e523b..2913901bbd01 100644 --- a/docs/pages/api-docs/data-grid/grid-virtualization-api.json +++ b/docs/pages/api-docs/data-grid/grid-virtualization-api.json @@ -1,7 +1,12 @@ { "name": "GridVirtualizationApi", - "description": "The virtualization API interface that is available in the grid.", + "description": "The virtualization API interface that is available in the grid apiRef.", "properties": [ + { + "name": "getScrollPosition", + "description": "Returns the current scroll position.", + "type": "() => GridScrollParams" + }, { "name": "scroll", "description": "Triggers the viewport to scroll to the given positions (in pixels).", @@ -9,18 +14,8 @@ }, { "name": "scrollToIndexes", - "description": "Triggers the viewport to scroll to the cell at indexes given by params. Returns true if the grid had to scroll to reach the target.", - "type": "(params: Optional) => boolean" - }, - { - "name": "getScrollPosition", - "description": "Returns the current scroll position.", - "type": "() => GridScrollParams" - }, - { - "name": "updateViewport", - "description": "Refreshes the viewport cells according to the scroll positions.", - "type": "(forceRender?: boolean) => void" + "description": "Triggers the viewport to scroll to the cell at indexes given by params.\nReturns true if the grid had to scroll to reach the target.", + "type": "(params: Partial) => boolean" } ] } diff --git a/docs/scripts/buildApi.ts b/docs/scripts/buildApi.ts index 4208543a44db..dcd66c5c9883 100644 --- a/docs/scripts/buildApi.ts +++ b/docs/scripts/buildApi.ts @@ -252,6 +252,7 @@ function run(argv: { outputDirectory?: string }) { 'GridFilterApi', 'GridCsvExportApi', 'GridExportCsvOptions', + 'GridVirtualizationApi', ]; apisToGenerate.forEach((apiName) => {