Skip to content

Commit 033da0d

Browse files
authored
Add docs (adazzle#3760)
1 parent de086c9 commit 033da0d

File tree

3 files changed

+178
-73
lines changed

3 files changed

+178
-73
lines changed

README.md

Lines changed: 124 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
[ci-badge]: https://github.com/adazzle/react-data-grid/workflows/CI/badge.svg
1717
[ci-url]: https://github.com/adazzle/react-data-grid/actions
1818

19+
The DataGrid component is designed to handle large datasets efficiently while offering a rich set of features for customization and interactivity.
20+
1921
## Features
2022

2123
- [React 19.0+](package.json) support
@@ -25,7 +27,7 @@
2527
- Strictly typed with TypeScript
2628
- [Keyboard accessibility](<(https://adazzle.github.io/react-data-grid/#/CommonFeatures)>)
2729
- Light and dark mode support out of the box. The light or dark themes can be enforced using the `rdg-light` or `rdg-dark` classes.
28-
- [Frozen columns](https://adazzle.github.io/react-data-grid/#/CommonFeatures)
30+
- [Frozen columns](https://adazzle.github.io/react-data-grid/#/CommonFeatures): Freeze columns to keep them visible during horizontal scrolling.
2931
- [Column resizing](https://adazzle.github.io/react-data-grid/#/CommonFeatures)
3032
- [Multi-column sorting](https://adazzle.github.io/react-data-grid/#/CommonFeatures)
3133
- Click on a sortable column header to toggle between its ascending/descending sort order
@@ -42,7 +44,7 @@
4244
- [Cell copy / pasting](https://adazzle.github.io/react-data-grid/#/AllFeatures)
4345
- [Cell value dragging / filling](https://adazzle.github.io/react-data-grid/#/AllFeatures)
4446
- [Customizable Renderers](https://adazzle.github.io/react-data-grid/#/CustomizableRenderers)
45-
- Right-to-left (RTL) support. We recommend using Firefox as Chrome has a [bug](https://issues.chromium.org/issues/40653832) with frozen columns.
47+
- Right-to-left (RTL) support.
4648

4749
## Links
4850

@@ -51,15 +53,27 @@
5153
- [Changelog](CHANGELOG.md)
5254
- [Contributing](CONTRIBUTING.md)
5355

54-
## Install
56+
## Installation
57+
58+
to install `react-data-grid`, use npm or yarn:
5559

5660
```sh
5761
npm install react-data-grid
62+
# or
63+
yarn add react-data-grid
64+
```
65+
66+
Additionally, import the default styles in your application:
67+
68+
```jsx
69+
import 'react-data-grid/lib/styles.css';
5870
```
5971

6072
`react-data-grid` is published as ECMAScript modules for evergreen browsers, bundlers, and server-side rendering.
6173

62-
## Quick start
74+
## Getting started
75+
76+
Here is a basic example of how to use `react-data-grid` in your React application:
6377

6478
```jsx
6579
import 'react-data-grid/lib/styles.css';
@@ -81,7 +95,7 @@ function App() {
8195
}
8296
```
8397

84-
## API
98+
## API Reference
8599

86100
### Components
87101

@@ -93,7 +107,7 @@ function App() {
93107

94108
See [`Column`](#column).
95109

96-
An array describing the grid's columns.
110+
An array of column definitions. Each column should have a key and name.
97111

98112
:warning: Passing a new `columns` array will trigger a re-render for the whole grid, avoid changing it as much as possible for optimal performance.
99113

@@ -103,15 +117,15 @@ An array of rows, the rows data can be of any type.
103117

104118
###### `topSummaryRows?: Maybe<readonly SR[]>`
105119

106-
An optional array of summary rows, usually used to display total values for example. `topSummaryRows` are pinned at the top of the rows view and the vertical scroll bar will not scroll these rows.
120+
Rows pinned at the top of the grid for summary purposes.
107121

108122
###### `bottomSummaryRows?: Maybe<readonly SR[]>`
109123

110-
An optional array of summary rows, usually used to display total values for example. `bottomSummaryRows` are pinned at the bottom of the rows view and the vertical scroll bar will not scroll these rows.
124+
Rows pinned at the bottom of the grid for summary purposes.
111125

112126
###### `rowKeyGetter?: Maybe<(row: R) => K>`
113127

114-
A function returning a unique key/identifier per row. `rowKeyGetter` is required for row selection to work.
128+
Function to return a unique key/identifier for each row. `rowKeyGetter` is required for row selection to work.
115129

116130
```tsx
117131
import { DataGrid } from 'react-data-grid';
@@ -134,7 +148,8 @@ function MyGrid() {
134148

135149
###### `onRowsChange?: Maybe<(rows: R[], data: RowsChangeData<R, SR>) => void>`
136150

137-
A function receiving row updates.
151+
Callback triggered when rows are changed.
152+
138153
The first parameter is a new rows array with both the updated rows and the other untouched rows.
139154
The second parameter is an object with an `indexes` array highlighting which rows have changed by their index, and the `column` where the change happened.
140155

@@ -153,31 +168,31 @@ function MyGrid() {
153168

154169
**Default:** `35` pixels
155170

156-
Either a number defining the height of row in pixels, or a function returning dynamic row heights.
171+
Height of each row in pixels. A function can be used to set different row heights.
157172

158173
###### `headerRowHeight?: Maybe<number>`
159174

160175
**Default:** `35` pixels
161176

162-
A number defining the height of the header row.
177+
Height of the header row in pixels.
163178

164179
###### `summaryRowHeight?: Maybe<number>`
165180

166181
**Default:** `35` pixels
167182

168-
A number defining the height of summary rows.
183+
Height of each summary row in pixels.
169184

170185
###### `selectedRows?: Maybe<ReadonlySet<K>>`
171186

172187
A set of selected row keys. `rowKeyGetter` is required for row selection to work.
173188

174189
###### `isRowSelectionDisabled?: Maybe<(row: NoInfer<R>) => boolean>`
175190

176-
A function used to disable row selection on certain rows.
191+
Function to determine if row selection is disabled for a specific row.
177192

178193
###### `onSelectedRowsChange?: Maybe<(selectedRows: Set<K>) => void>`
179194

180-
A function called when row selection is changed.
195+
Callback triggered when the selection changes.
181196

182197
```tsx
183198
import { useState } from 'react';
@@ -220,7 +235,7 @@ An array of sorted columns.
220235

221236
###### `onSortColumnsChange?: Maybe<(sortColumns: SortColumn[]) => void>`
222237

223-
A function called when sorting is changed
238+
Callback triggered when sorting changes.
224239

225240
```tsx
226241
import { useState } from 'react';
@@ -261,7 +276,7 @@ onSortColumnsChange(sortColumns: SortColumn[]) {
261276

262277
###### `defaultColumnOptions?: Maybe<DefaultColumnOptions<R, SR>>`
263278

264-
Column options that are applied to all the columns
279+
Default options applied to all columns.
265280

266281
```tsx
267282
function MyGrid() {
@@ -284,7 +299,7 @@ function MyGrid() {
284299

285300
###### `onCellClick?: Maybe<(args: CellClickArgs<R, SR>, event: CellMouseEvent) => void>`
286301

287-
Triggered when a cell is clicked. The default behavior is to select the cell. Call `preventGridDefault` to prevent the default behavior
302+
Callback triggered when a cell is clicked. The default behavior is to select the cell. Call `preventGridDefault` to prevent the default behavior
288303

289304
```tsx
290305
function onCellClick(args: CellClickArgs<R, SR>, event: CellMouseEvent) {
@@ -323,7 +338,7 @@ Arguments:
323338

324339
###### `onCellDoubleClick?: Maybe<(args: CellClickArgs<R, SR>, event: CellMouseEvent) => void>`
325340

326-
Triggered when a cell is double clicked. The default behavior is to open the editor if the cell is editable. Call `preventGridDefault` to prevent the default behavior
341+
Callback triggered when a cell is double-clicked. The default behavior is to open the editor if the cell is editable. Call `preventGridDefault` to prevent the default behavior
327342

328343
```tsx
329344
function onCellDoubleClick(args: CellClickArgs<R, SR>, event: CellMouseEvent) {
@@ -337,7 +352,7 @@ function onCellDoubleClick(args: CellClickArgs<R, SR>, event: CellMouseEvent) {
337352

338353
###### `onCellContextMenu?: Maybe<(args: CellClickArgs<R, SR>, event: CellMouseEvent) => void>`
339354

340-
Triggered when a cell is right clicked. The default behavior is to select the cell. Call `preventGridDefault` to prevent the default behavior
355+
Callback triggered when a cell is right-clicked. The default behavior is to select the cell. Call `preventGridDefault` to prevent the default behavior
341356

342357
```tsx
343358
function onCellContextMenu(args: CellClickArgs<R, SR>, event: CellMouseEvent) {
@@ -379,11 +394,11 @@ Check [more examples](website/routes/CellNavigation.tsx)
379394

380395
###### `onCellCopy?: Maybe<(args: CellCopyEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void>`
381396

382-
A function called when copy event is triggered on a cell
397+
Callback triggered when a cell's content is copied.
383398

384399
###### `onCellPaste?: Maybe<(args: CellPasteEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void>`
385400

386-
A function called when paste event is triggered on a cell
401+
Callback triggered when content is pasted into a cell.
387402

388403
###### `onSelectedCellChange?: Maybe<(args: CellSelectArgs<R, SR>) => void>;`
389404

@@ -397,11 +412,15 @@ Arguments:
397412

398413
###### `onScroll?: Maybe<(event: React.UIEvent<HTMLDivElement>) => void>`
399414

400-
A function called when the grid is scrolled.
415+
Callback triggered when the grid is scrolled.
401416

402417
###### `onColumnResize?: Maybe<(column: CalculatedColumn<R, SR>, width: number) => void>`
403418

404-
A function called when column is resized.
419+
Callback triggered when column is resized.
420+
421+
###### `onColumnsReorder?: Maybe<(sourceColumnKey: string, targetColumnKey: string) => void>`
422+
423+
Callback triggered when columns are reordered.
405424

406425
###### `enableVirtualization?: Maybe<boolean>`
407426

@@ -411,7 +430,7 @@ This prop can be used to disable virtualization.
411430

412431
###### `renderers?: Maybe<Renderers<R, SR>>`
413432

414-
This prop can be used to override the internal renderers. The prop accepts an object of type
433+
Custom renderers for cells, rows, and other components.
415434

416435
```tsx
417436
interface Renderers<TRow, TSummaryRow> {
@@ -445,7 +464,7 @@ function MyGrid() {
445464

446465
###### `rowClass?: Maybe<(row: R, rowIdx: number) => Maybe<string>>`
447466

448-
A function to add a class on the row
467+
Function to apply custom class names to rows.
449468

450469
```tsx
451470
import { DataGrid } from 'react-data-grid';
@@ -461,6 +480,8 @@ function rowClass(row: Row, rowIdx: number) {
461480

462481
###### `headerRowClass?: Maybe<string>>`
463482

483+
Custom class name for the header row.
484+
464485
###### `direction?: Maybe<'ltr' | 'rtl'>`
465486

466487
This property sets the text direction of the grid, it defaults to `'ltr'` (left-to-right). Setting `direction` to `'rtl'` has the following effects:
@@ -472,11 +493,11 @@ This property sets the text direction of the grid, it defaults to `'ltr'` (left-
472493

473494
###### `className?: string | undefined`
474495

475-
custom classname
496+
Custom class name for the grid.
476497

477498
###### `style?: CSSProperties | undefined`
478499

479-
custom styles
500+
Custom styles for the grid.
480501

481502
###### `'aria-label'?: string | undefined`
482503

@@ -600,7 +621,7 @@ See [`RenderGroupCellProps`](#rendergroupcellprops)
600621

601622
##### `name: string | ReactElement`
602623

603-
The name of the column. By default it will be displayed in the header cell
624+
The name of the column. Displayed in the header cell by default.
604625

605626
##### `key: string`
606627

@@ -625,31 +646,97 @@ width: 'minmax(100px, max-content)';
625646

626647
**Default**: `50` pixels
627648

628-
Sets the maximum width of a column.
649+
Minimum column width in pixels.
629650

630651
##### `maxWidth?: Maybe<number>`
631652

632-
Sets the maximum width of a column.
653+
Maximum column width in pixels.
633654

634655
##### `cellClass?: Maybe<string | ((row: TRow) => Maybe<string>)>`
635656

636-
A function to add a class on the row
657+
Class name(s) for the cell
637658

638659
##### `headerCellClass?: Maybe<string>`
639660

661+
Class name(s) for the header cell.
662+
640663
##### `summaryCellClass?: Maybe<string | ((row: TSummaryRow) => Maybe<string>)>`
641664

665+
Class name(s) for the summary cell.
666+
642667
##### `renderCell?: Maybe<(props: RenderCellProps<TRow, TSummaryRow>) => ReactNode>`
643668

644-
Render function used to render the content of cells
669+
Render function to render the content of cells.
670+
671+
##### `renderHeaderCell?: Maybe<(props: RenderHeaderCellProps<TRow, TSummaryRow>) => ReactNode>`
672+
673+
Render function to render the content of the header cell.
674+
675+
##### `renderSummaryCell?: Maybe<(props: RenderSummaryCellProps<TSummaryRow, TRow>) => ReactNode>`
676+
677+
Render function to render the content of summary cells
678+
679+
##### `renderEditCell?: Maybe<(props: RenderEditCellProps<TRow, TSummaryRow>) => ReactNode>`
680+
681+
Render function to render the content of edit cells. When set, the column is automatically set to be editable
682+
683+
##### `editable?: Maybe<boolean | ((row: TRow) => boolean)>`
684+
685+
Enables cell editing. If set and no editor property specified, then a textinput will be used as the cell editor.
686+
687+
##### `colSpan?: Maybe<(args: ColSpanArgs<TRow, TSummaryRow>) => Maybe<number>>`
688+
689+
##### `frozen?: Maybe<boolean>`
690+
691+
**Default**: `false`
692+
693+
Determines whether column is frozen. Frozen columns are pinned on the left. At the moment we do not support pinning columns on the right.
694+
695+
##### `resizable?: Maybe<boolean>`
696+
697+
**Default**: `false`
698+
699+
Enable resizing of the column
700+
701+
##### `sortable?: Maybe<boolean>`
702+
703+
**Default**: `false`
704+
705+
Enable sorting of the column
706+
707+
##### `draggable?: Maybe<boolean>`
708+
709+
**Default**: `false`
710+
711+
Enable dragging of the column
712+
713+
##### `sortDescendingFirst?: Maybe<boolean>`
714+
715+
**Default**: `false`
716+
717+
Sets the column sort order to be descending instead of ascending the first time the column is sorted
718+
719+
##### `editorOptions`
720+
721+
Options for cell editing.
722+
723+
###### `displayCellContent?: Maybe<boolean>`
724+
725+
**Default**: `false`
726+
727+
Render the cell content in addition to the edit cell. Enable this option when the editor is rendered outside the grid, like a modal for example.
728+
729+
###### `commitOnOutsideClick?: Maybe<boolean>`
730+
731+
**Default**: `true`
645732

646-
##### `renderHeaderCell`
733+
Commit changes when clicking outside the cell.
647734

648-
Render function used to render the content of header cells
735+
###### `closeOnExternalRowChange?: Maybe<boolean>`
649736

650-
##### `renderSummaryCell`
737+
**Default**: `true`
651738

652-
Render function used to render the content of summary cells
739+
Close the editor when the row changes externally.
653740

654741
#### `DataGridHandle`
655742

0 commit comments

Comments
 (0)