### Install AG Grid React Data Grid
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/index
Install the `ag-grid-react` package using npm. This command also installs the `ag-grid-community` package as a dependency, providing the core AG Grid functionality.
```bash
npm install ag-grid-react
```
--------------------------------
### Complete AG Grid React Data Grid Example
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/index
This is a full example of a React Data Grid using AG Grid. It includes necessary imports, module registration, state management for row data and column definitions, default column definitions, and the rendering of the `AgGridReact` component within a container. It also demonstrates how to render the grid using `createRoot` from `react-dom/client`.
```javascript
'use client';
import React, { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";
import { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
import { AgGridReact } from "ag-grid-react";
ModuleRegistry.registerModules([AllCommunityModule]);
// Create new GridExample component
const GridExample = () => {
// Row Data: The data to be displayed.
const [rowData, setRowData] = useState([
{ make: "Tesla", model: "Model Y", price: 64950, electric: true },
{ make: "Ford", model: "F-Series", price: 33850, electric: false },
{ make: "Toyota", model: "Corolla", price: 29600, electric: false },
{ make: "Mercedes", model: "EQA", price: 48890, electric: true },
{ make: "Fiat", model: "500", price: 15774, electric: false },
{ make: "Nissan", model: "Juke", price: 20675, electric: false },
]);
// Column Definitions: Defines & controls grid columns.
const [colDefs, setColDefs] = useState([
{ field: "make" },
{ field: "model" },
{ field: "price" },
{ field: "electric" },
]);
const defaultColDef = {
flex: 1,
};
// Container: Defines the grid's theme & dimensions.
return (
);
};
// Render GridExample
const root = createRoot(document.getElementById("root"));
root.render(
,
);
```
--------------------------------
### Import AG Grid React Component
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/index
Import the `AgGridReact` component from the `ag-grid-react` package. This component is the main entry point for using AG Grid in your React application.
```javascript
import { AgGridReact } from 'ag-grid-react'; // React Data Grid Component
```
--------------------------------
### Register AG Grid Community Modules
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/index
Register the `AllCommunityModule` to enable all community features within your AG Grid React application. This is a crucial step for accessing the grid's functionalities.
```javascript
import { AllCommunityModule, ModuleRegistry } from 'ag-grid-community';
// Register all Community features
ModuleRegistry.registerModules([AllCommunityModule]);
```
--------------------------------
### Custom Theme Configuration in React
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/archive/33.2
Demonstrates how to create a custom theme for AG Grid in a React application using the theming API. This allows for fine-grained control over grid styling, such as spacing, by extending built-in themes like 'Quartz'.
```javascript
// Using the Theming API
import { themeQuartz } from 'ag-grid-community';
const myTheme = themeQuartz.withParams({
"spacing": 8
});
```
--------------------------------
### Define Rows and Columns for AG Grid React
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/index
This snippet demonstrates how to define the row data and column definitions for the AG Grid React component. It uses the `useState` hook to manage the data and column configurations.
```javascript
const GridExample = () => {
// Row Data: The data to be displayed.
const [rowData, setRowData] = useState([
{ make: "Tesla", model: "Model Y", price: 64950, electric: true },
{ make: "Ford", model: "F-Series", price: 33850, electric: false },
{ make: "Toyota", model: "Corolla", price: 29600, electric: false },
]);
// Column Definitions: Defines the columns to be displayed.
const [colDefs, setColDefs] = useState([
{ field: "make" },
{ field: "model" },
{ field: "price" },
{ field: "electric" }
]);
// ...
}
```
--------------------------------
### Render AG Grid React Component
Source: https://ag-grid.com/archive/33.2.3/react-data-grid/getting-started/index
This code snippet shows how to return the `AgGridReact` component within a parent div. The parent div is styled with a fixed height to control the grid's dimensions. The `rowData` and `columnDefs` are passed as props to the `AgGridReact` component.
```jsx
return (
// Data Grid will fill the size of the parent container
)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.