Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit a3254a5

Browse files
Update data grid docs (#457)
Description of changes Updates data grid docs to better clarify that the rowsData method does not work when using the React toolkit components and provides an example of how to create data grids when using React.
1 parent b483a33 commit a3254a5

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/data-grid/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ For example, if you're using a data grid to display real-time earthquake data, a
5353

5454
### Basic Data Grid
5555

56-
The recommended basic usage of the `vscode-data-grid` is to use JavaScript (or TypeScript) to programmatically populate the rows and cells of the grid using the `rowsData` property as shown below.
56+
The recommended basic usage of the `vscode-data-grid` is to use JavaScript (or TypeScript) to programmatically populate the rows and cells of the grid using the `rowsData` property as shown below. _Notable exception: The `rowsData` property doesn't work at this time when using the React toolkit components –– see below for an alternative approach._
5757

5858
With that said, a data grid can still be created with HTML only (also shown below).
5959

@@ -79,6 +79,8 @@ document.getElementById("basic-grid").rowsData = [
7979

8080
_Using Only HTML_
8181

82+
This is the recommended way of creating data grids when using React.
83+
8284
Note: When defining data grids using only HTML, a header row must be manually defined (as demonstrated below).
8385

8486
Additionally, in previous versions of the toolkit (less than or equal to `v0.9.1`), an attribute of `generate-header="none"` needs to be applied to the `vscode-data-grid` component. This ensures that an extra empty header row is not automatically generated.
@@ -114,6 +116,47 @@ Starting in `v0.9.2`, however, this behavior has changed so a header row is not
114116
</vscode-data-grid>
115117
```
116118

119+
Here's a further example of how you might use React's templating syntax to programmatically generate data rows.
120+
121+
```jsx
122+
import { VSCodeDataGrid, VSCodeDataGridRow, VSCodeDataGridCell } from "@vscode/webview-ui-toolkit/react";
123+
124+
function SomeComponent() {
125+
const rowData = [
126+
{ cell1: "Cell Data", cell2: "Cell Data", cell3: "Cell Data", cell4: "Cell Data" },
127+
{ cell1: "Cell Data", cell2: "Cell Data", cell3: "Cell Data", cell4: "Cell Data" },
128+
{ cell1: "Cell Data", cell2: "Cell Data", cell3: "Cell Data", cell4: "Cell Data" },
129+
];
130+
131+
return (
132+
<VSCodeDataGrid>
133+
<VSCodeDataGridRow row-type="header">
134+
<VSCodeDataGridCell cell-type="columnheader" grid-column="1">
135+
A Custom Header Title
136+
</VSCodeDataGridCell>
137+
<VSCodeDataGridCell cell-type="columnheader" grid-column="2">
138+
Another Custom Title
139+
</VSCodeDataGridCell>
140+
<VSCodeDataGridCell cell-type="columnheader" grid-column="3">
141+
Title Is Custom
142+
</VSCodeDataGridCell>
143+
<VSCodeDataGridCell cell-type="columnheader" grid-column="4">
144+
Custom Title
145+
</VSCodeDataGridCell>
146+
</VSCodeDataGridRow>
147+
{rowData.map(row => (
148+
<VSCodeDataGridRow>
149+
<VSCodeDataGridCell grid-column="1">{row.cell1}</VSCodeDataGridCell>
150+
<VSCodeDataGridCell grid-column="2">{row.cell2}</VSCodeDataGridCell>
151+
<VSCodeDataGridCell grid-column="3">{row.cell3}</VSCodeDataGridCell>
152+
<VSCodeDataGridCell grid-column="4">{row.cell4}</VSCodeDataGridCell>
153+
</VSCodeDataGridRow>
154+
))}
155+
</VSCodeDataGrid>
156+
);
157+
}
158+
```
159+
117160
### Generate Header Attribute
118161

119162
The `generate-header` attribute is applied to the `<vscode-data-grid>` component and can be used to automatically generate a header row when data is passed to the `rowsData` property in JavaScript.

0 commit comments

Comments
 (0)