---
title: "Creating a Basic Grid"
framework: react
version: "36.1.0"
---

# Creating a Basic Grid

Learn how to create and configure an AG Grid instance from scratch. This guide introduces the essential concepts required to build an interactive grid, including setting up row data, defining columns, applying grid options, formatting cell values, and adding custom components.

## Overview

In this tutorial you will:

1. [Create a basic grid](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#create-a-basic-grid)
2. [Load external data into the grid](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#load-new-data)
3. [Configure columns](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#configure-columns)
4. [Configure grid features](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#configure-the-grid)
5. [Format cell values](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#format-cell-values)
6. [Add custom components to cells](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#custom-cell-components)
7. [Hook into grid events](https://www.ag-grid.com/archive/36.1.0/react-data-grid/deep-dive/#handle-grid-events)

Once complete, you'll have an interactive grid, with custom components and formatted data - Try it out for yourself by **sorting**, **filtering**, **resizing**, **selecting**, or **editing** data in the grid:

#### Testing Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type {
  ColDef,
  RowSelectionOptions,
  ValueFormatterParams,
} from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import type { CustomCellRendererProps } from "ag-grid-react";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Custom Cell Renderer (Display logos based on cell value)
const CompanyLogoRenderer = (params: CustomCellRendererProps) => (
  <span
    style={{
      display: "flex",
      height: "100%",
      width: "100%",
      alignItems: "center",
    }}
  >
    {params.value && (
      <img
        alt={`${params.value} Flag`}
        src={`https://www.ag-grid.com/example-assets/space-company-logos/${params.value.toLowerCase()}.png`}
        style={{
          display: "block",
          width: "25px",
          height: "auto",
          maxHeight: "50%",
          marginRight: "12px",
          filter: "brightness(1.1)",
        }}
      />
    )}
    <p
      style={{
        textOverflow: "ellipsis",
        overflow: "hidden",
        whiteSpace: "nowrap",
      }}
    >
      {params.value}
    </p>
  </span>
);

/* Custom Cell Renderer (Display tick / cross in 'Successful' column) */
const MissionResultRenderer = (params: CustomCellRendererProps) => (
  <span
    style={{
      display: "flex",
      justifyContent: "center",
      height: "100%",
      alignItems: "center",
    }}
  >
    {
      <img
        alt={`${params.value}`}
        src={`https://www.ag-grid.com/example-assets/icons/${params.value ? "tick-in-circle" : "cross-in-circle"}.png`}
        style={{ width: "auto", height: "auto" }}
      />
    }
  </span>
);

/* Format Date Cells */
const dateFormatter = (params: ValueFormatterParams): string => {
  return new Date(params.value).toLocaleDateString("en-us", {
    weekday: "long",
    year: "numeric",
    month: "short",
    day: "numeric",
  });
};

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

const rowSelection: RowSelectionOptions = {
  mode: "multiRow",
  headerCheckbox: false,
};

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    {
      field: "mission",
      width: 150,
    },
    {
      field: "company",
      width: 130,
      cellRenderer: CompanyLogoRenderer,
    },
    {
      field: "location",
      width: 225,
    },
    {
      field: "date",
      valueFormatter: dateFormatter,
    },
    {
      field: "price",
      width: 130,
      valueFormatter: (params: ValueFormatterParams) => {
        return "£" + params.value.toLocaleString();
      },
    },
    {
      field: "successful",
      width: 120,
      cellRenderer: MissionResultRenderer,
    },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
      editable: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
          pagination={true}
          rowSelection={rowSelection}
          onSelectionChanged={(event) => console.log("Row Selected!")}
          onCellValueChanged={(event) =>
            console.log(`New Cell Value: ${event.value}`)
          }
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Testing Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/testing-example/reactFunctionalTs)

## Create a Basic Grid

Complete our [Quick Start](https://www.ag-grid.com/archive/36.1.0/react-data-grid/getting-started/) (or open the example below in CodeSandbox / Plunker) to start with a basic grid, comprised of:

1. **Row Data:** The data to be displayed.
2. **Column Definition:** Defines & controls grid columns.
3. **Container:** A div that contains the grid and defines its dimensions.
4. **Grid Component:** The `AgGridReact` component with **Row Data** and **Column Definition** props.

#### Basic Example

```tsx
'use client';
// React Grid Logic
import React, { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

// Theme
import type { ColDef } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
// Core CSS
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Row Data Interface
interface IRow {
  make: string;
  model: string;
  price: number;
  electric: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const [rowData, setRowData] = useState<IRow[]>([
    { 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 & controls grid columns.
  const [colDefs, setColDefs] = useState<ColDef<IRow>[]>([
    { field: "make" },
    { field: "model" },
    { field: "price" },
    { field: "electric" },
  ]);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        <AgGridReact rowData={rowData} columnDefs={colDefs} />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Basic Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/basic-example/reactFunctionalTs)

*Note: `rowData` and `columnDefs` arrays use the `useState` hook. We recommend `useState` if the data is mutable, otherwise `useMemo` is preferable. Read our [Best Practices](https://www.ag-grid.com/archive/36.1.0/react-data-grid/react-hooks/) guide to learn more about using React hooks with AG Grid.*

## Load New Data

As `rowData` is a reactive property, any updates to its state will be reflected in the grid. Let's test this by fetching some data from an external server and updating `rowData` with the response:

```jsx
// Fetch data & update rowData state
useEffect(() => {
    fetch('https://www.ag-grid.com/example-assets/space-mission-data.json') // Fetch data from server
        .then(result => result.json()) // Convert to JSON
        .then(rowData => setRowData(rowData)); // Update state of `rowData`
}, [])
```

Now that we're loading data from an external source, we can empty our `rowData` array (which will allow the grid to display a loading spinner whilst the data is being fetched) and update our `colDefs` to match the new dataset:

```jsx
const GridExample = () => {
    // Row Data: The data to be displayed.
    const [rowData, setRowData] = useState([]);
    const [colDefs, setColDefs] = useState([
        { field: "mission" },
        { field: "company" },
        { field: "location" },
        { field: "date" },
        { field: "price" },
        { field: "successful" },
        { field: "rocket" }
    ]);
    // ...
}
```

When we run our application, we should see a grid with ~1,400 rows of new data, and new column headers to match:

#### Updating Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    { field: "mission" },
    { field: "company" },
    { field: "location" },
    { field: "date" },
    { field: "price" },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact rowData={data} loading={loading} columnDefs={colDefs} />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Updating Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/updating-example/reactFunctionalTs)

*Note: All properties that are not tagged as 'initial' are reactive. See our [API docs](https://www.ag-grid.com/archive/36.1.0/react-data-grid/grid-options/) for a complete list.*

## Configure Columns

Now that we have a basic grid with some arbitrary data, we can start to configure the grid with ***Column Properties***.

Column Properties can be added to one or more columns to enable/disable column-specific features. Let's try this by adding the `filter: true` property to the 'mission' column:

```jsx
const [colDefs] = useState([
    { field: "mission", filter: true },
    // ...
]);
```

We should now be able to filter the 'mission' column - you can test this by filtering for the 'Apollo' missions:

#### Configuring Columns Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    { field: "mission", filter: true },
    { field: "company" },
    { field: "location" },
    { field: "date" },
    { field: "price" },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact rowData={data} loading={loading} columnDefs={colDefs} />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Configuring Columns Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/configure-columns-example/reactFunctionalTs)

*Note: Column properties can be used to configure a wide-range of features; refer to our [Column Properties](https://www.ag-grid.com/archive/36.1.0/react-data-grid/column-properties/) page for a full list of features.*

### Default Column Definitions

The example above demonstrates how to configure a single column. To apply this configuration across all columns we can use ***Default Column Definitions*** instead. Let's make all of our columns filterable by creating a `defaultColDef` object, setting `filter: true`, and passing this to the grid via the `defaultColDef` prop:

```jsx
// Apply settings across all columns
const defaultColDef = useMemo(() => ({
    filter: true // Enable filtering on all columns
}))

<div style={{ width: 600, height: 500 }}>
    <AgGridReact
        defaultColDef={defaultColDef}
        //...
    />
</div>
```

The grid should now allow filtering on all columns:

#### Default Column Definitions Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    { field: "mission", filter: true },
    { field: "company" },
    { field: "location" },
    { field: "date" },
    { field: "price" },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Default Column Definitions Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/default-columns-example/reactFunctionalTs)

*Note: Column Definitions take precedence over Default Column Definitions*

## Configure The Grid

So far we've covered creating a grid, updating the data within the grid, and configuring columns. This section introduces **Grid Options**, which control functionality that extends across both rows & columns, such as Pagination and Row Selection.

Grid Options are passed to the grid component directly as props. Let's enable pagination by adding `pagination={true}`:

```jsx
<div style={{ width: 600, height: 500 }}>
    <AgGridReact
        // ...
        pagination={true} // Enable Pagination
    />
</div>
```

We should now see Pagination has been enabled on the grid:

#### Grid Options Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    { field: "mission", filter: true },
    { field: "company" },
    { field: "location" },
    { field: "date" },
    { field: "price" },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
          pagination={true}
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Grid Options Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/grid-options-example/reactFunctionalTs)

*Refer to our detailed [Grid Options](https://www.ag-grid.com/archive/36.1.0/react-data-grid/grid-options/) documentation for a full list of options.*

## Format Cell Values

The data supplied to the grid usually requires some degree of formatting. For basic text formatting we can use **Value Formatters**.

**Value Formatters** are basic functions which take the value of the cell, apply some basic formatting, and return a new value to be displayed by the grid. Let's try this by adding the `valueFormatter` property to our 'price' column and returning the formatted value:

```jsx
const [colDefs] = useState([
    {
        field: "price",
        // Return a formatted string for this column
        valueFormatter: params => { return '£' + params.value.toLocaleString(); }
    },
    // ...
]);
```

The grid should now show the formatted value in the 'price' column:

#### Value Formatter Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef, ValueFormatterParams } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    {
      field: "mission",
      filter: true,
    },
    { field: "company" },
    { field: "location" },
    { field: "date" },
    {
      field: "price",
      valueFormatter: (params: ValueFormatterParams) => {
        return "£" + params.value.toLocaleString();
      },
    },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
          pagination={true}
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Value Formatter Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/value-formatter-example/reactFunctionalTs)

*Note: Read our [Value Formatter](https://www.ag-grid.com/archive/36.1.0/react-data-grid/value-formatters/) page for more information on formatting cell values*

## Custom Cell Components

**Value Formatters** are useful for basic formatting, but for more advanced use-cases we can use **Cell Renderers** instead.

**Cell Renderers** allow you to use your own React components within cells. To use a custom component, set the `cellRenderer` prop on a column, with the value as the name of your component.

Let's try this by creating a new component to display the company logo in the 'company' column:

```jsx
// Custom Cell Renderer (Display flags based on cell value)
const CompanyLogoRenderer = ({ value }) => (
    <span style={{ display: "flex", height: "100%", width: "100%", alignItems: "center" }}>{value && <img alt={`${value} Flag`} src={`https://www.ag-grid.com/example-assets/space-company-logos/${value.toLowerCase()}.png`} style={{display: "block", width: "25px", height: "auto", maxHeight: "50%", marginRight: "12px", filter: "brightness(1.1)"}} />}<p style={{ textOverflow: "ellipsis", overflow: "hidden", whiteSpace: "nowrap" }}>{value}</p></span>
);
```

And then adding the `cellRenderer` prop on our 'company' column to use our component:

```jsx
const [colDefs] = useState([
    {
        field: "company",
        // Add component to column via cellRenderer
        cellRenderer: CompanyLogoRenderer
    },
    // ...
]);
```

Now, when we run the grid, we should see a company logo next to the name:

#### Cell Renderer Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef, ValueFormatterParams } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import type { CustomCellRendererProps } from "ag-grid-react";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Custom Cell Renderer (Display logos based on cell value)
const CompanyLogoRenderer = (params: CustomCellRendererProps) => (
  <span
    style={{
      display: "flex",
      height: "100%",
      width: "100%",
      alignItems: "center",
    }}
  >
    {params.value && (
      <img
        alt={`${params.value} Flag`}
        src={`https://www.ag-grid.com/example-assets/space-company-logos/${params.value.toLowerCase()}.png`}
        style={{
          display: "block",
          width: "25px",
          height: "auto",
          maxHeight: "50%",
          marginRight: "12px",
          filter: "brightness(1.1)",
        }}
      />
    )}
    <p
      style={{
        textOverflow: "ellipsis",
        overflow: "hidden",
        whiteSpace: "nowrap",
      }}
    >
      {params.value}
    </p>
  </span>
);

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    {
      field: "mission",
      filter: true,
    },
    {
      field: "company",
      cellRenderer: CompanyLogoRenderer,
    },
    {
      field: "location",
    },
    { field: "date" },
    {
      field: "price",
      valueFormatter: (params: ValueFormatterParams) => {
        return "£" + params.value.toLocaleString();
      },
    },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
          pagination={true}
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Cell Renderer Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/cell-renderer-example/reactFunctionalTs)

*Note: Read our [Cell Components](https://www.ag-grid.com/archive/36.1.0/react-data-grid/component-cell-renderer/) page for more information on using custom components in cells*

## Handle Grid Events

In the last section of this tutorial we're going to hook into events raised by the grid using ***Grid Events***.

To be notified of when an event is raised by the grid we need to use the relevant `on[EventName]` prop on the grid component. Let's try this out by enabling cell editing with `editable: true` and hooking into the `onCellValueChanged` event to log the new value to the console:

```jsx
const defaultColDef = useMemo(() => ({
    editable: true, // Enable editing on all cells
    // ...
}))

<div style={{ width: 600, height: 500 }}>
    <AgGridReact
        // Hook into CellValueChanged event and log value
        onCellValueChanged={event => console.log(`New Cell Value: ${event.value}`)}
        // ...
    />
</div>
```

Now, when we click on a cell we should be able to edit it and see the new value logged to the console:

#### Complete Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type { ColDef, ValueFormatterParams } from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import type { CustomCellRendererProps } from "ag-grid-react";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Custom Cell Renderer (Display logos based on cell value)
const CompanyLogoRenderer = (params: CustomCellRendererProps) => (
  <span
    style={{
      display: "flex",
      height: "100%",
      width: "100%",
      alignItems: "center",
    }}
  >
    {params.value && (
      <img
        alt={`${params.value} Flag`}
        src={`https://www.ag-grid.com/example-assets/space-company-logos/${params.value.toLowerCase()}.png`}
        style={{
          display: "block",
          width: "25px",
          height: "auto",
          maxHeight: "50%",
          marginRight: "12px",
          filter: "brightness(1.1)",
        }}
      />
    )}
    <p
      style={{
        textOverflow: "ellipsis",
        overflow: "hidden",
        whiteSpace: "nowrap",
      }}
    >
      {params.value}
    </p>
  </span>
);

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    {
      field: "mission",
      filter: true,
    },
    {
      field: "company",
      cellRenderer: CompanyLogoRenderer,
    },
    {
      field: "location",
    },
    { field: "date" },
    {
      field: "price",
      valueFormatter: (params: ValueFormatterParams) => {
        return "£" + params.value.toLocaleString();
      },
    },
    { field: "successful" },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
      editable: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        {/* The AG Grid component, with Row Data & Column Definition props */}
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
          pagination={true}
          onCellValueChanged={(event) =>
            console.log(`New Cell Value: ${event.value}`)
          }
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Complete Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/grid-events-example/reactFunctionalTs)

*Refer to our [Grid Events](https://www.ag-grid.com/archive/36.1.0/react-data-grid/grid-events/) documentation for a full list of events raised by the grid*

## Test Your Knowledge

Let's put what you've learned so far into action by modifying the grid:

1. Enable filtering on all columns

   *Hint: `filter` is a Column Definition property*
2. Enable multiple row selection

   *Hint: `rowSelection` is a Grid Option property*
3. Log a message to the console when a row selection is changed

   *Hint: `onSelectionChanged` is a Grid Event*
4. Format the Date column using `.toLocaleDateString()`;

   *Hint: Use a `valueFormatter` on the 'Date' column to format its value*
5. Add a Cell Renderer to display [ticks](https://www.ag-grid.com/example-assets/icons/tick-in-circle.png) and [crosses](https://www.ag-grid.com/example-assets/icons/cross-in-circle.png) in place of checkboxes on the 'Successful' column:

   *Hint: Use a `cellRenderer` on the 'successful' column*

Once complete, your grid should look like the example below. If you're stuck, check out the source code to see how its done:

#### Testing Example

```tsx
'use client';
import { useFetchJson } from './useFetchJson';
// React Grid Logic
import React, { StrictMode, useMemo, useState } from "react";
import { createRoot } from "react-dom/client";

import type {
  ColDef,
  RowSelectionOptions,
  ValueFormatterParams,
} from "ag-grid-community";
import { AllCommunityModule } from "ag-grid-community";
import type { CustomCellRendererProps } from "ag-grid-react";
import { AgGridProvider, AgGridReact } from "ag-grid-react";

// Custom Cell Renderer (Display logos based on cell value)
const CompanyLogoRenderer = (params: CustomCellRendererProps) => (
  <span
    style={{
      display: "flex",
      height: "100%",
      width: "100%",
      alignItems: "center",
    }}
  >
    {params.value && (
      <img
        alt={`${params.value} Flag`}
        src={`https://www.ag-grid.com/example-assets/space-company-logos/${params.value.toLowerCase()}.png`}
        style={{
          display: "block",
          width: "25px",
          height: "auto",
          maxHeight: "50%",
          marginRight: "12px",
          filter: "brightness(1.1)",
        }}
      />
    )}
    <p
      style={{
        textOverflow: "ellipsis",
        overflow: "hidden",
        whiteSpace: "nowrap",
      }}
    >
      {params.value}
    </p>
  </span>
);

/* Custom Cell Renderer (Display tick / cross in 'Successful' column) */
const MissionResultRenderer = (params: CustomCellRendererProps) => (
  <span
    style={{
      display: "flex",
      justifyContent: "center",
      height: "100%",
      alignItems: "center",
    }}
  >
    {
      <img
        alt={`${params.value}`}
        src={`https://www.ag-grid.com/example-assets/icons/${params.value ? "tick-in-circle" : "cross-in-circle"}.png`}
        style={{ width: "auto", height: "auto" }}
      />
    }
  </span>
);

/* Format Date Cells */
const dateFormatter = (params: ValueFormatterParams): string => {
  return new Date(params.value).toLocaleDateString("en-us", {
    weekday: "long",
    year: "numeric",
    month: "short",
    day: "numeric",
  });
};

// Row Data Interface
interface IRow {
  mission: string;
  company: string;
  location: string;
  date: string;
  time: string;
  rocket: string;
  price: number;
  successful: boolean;
}

const rowSelection: RowSelectionOptions = {
  mode: "multiRow",
  headerCheckbox: false,
};

// Create new GridExample component
const GridExample = () => {
  // Row Data: The data to be displayed.
  const { data, loading } = useFetchJson<IRow>(
    "https://www.ag-grid.com/example-assets/space-mission-data.json",
  );

  // Column Definitions: Defines & controls grid columns.
  const [colDefs] = useState<ColDef[]>([
    {
      field: "mission",
      width: 150,
    },
    {
      field: "company",
      width: 130,
      cellRenderer: CompanyLogoRenderer,
    },
    {
      field: "location",
      width: 225,
    },
    {
      field: "date",
      valueFormatter: dateFormatter,
    },
    {
      field: "price",
      width: 130,
      valueFormatter: (params: ValueFormatterParams) => {
        return "£" + params.value.toLocaleString();
      },
    },
    {
      field: "successful",
      width: 120,
      cellRenderer: MissionResultRenderer,
    },
    { field: "rocket" },
  ]);

  // Apply settings across all columns
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      filter: true,
      editable: true,
    };
  }, []);

  // Container: Defines the grid's theme & dimensions.
  return (
    <AgGridProvider modules={[AllCommunityModule]}>
      <div style={{ width: "100%", height: "100%" }}>
        <AgGridReact
          rowData={data}
          loading={loading}
          columnDefs={colDefs}
          defaultColDef={defaultColDef}
          pagination={true}
          rowSelection={rowSelection}
          onSelectionChanged={(event) => console.log("Row Selected!")}
          onCellValueChanged={(event) =>
            console.log(`New Cell Value: ${event.value}`)
          }
        />
      </div>
    </AgGridProvider>
  );
};

// Render GridExample
const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Testing Example](https://www.ag-grid.com/archive/36.1.0/examples/deep-dive/testing-example/reactFunctionalTs)

## Summary

Congratulations! You've completed the tutorial and built your first grid. By now, you should be familiar with the key concepts of AG Grid:

- **Row Data:** Your data, in JSON format, that you want the grid to display.
- **Column Definitions:** Define your columns and control column-specific functionality, like sorting and filtering.
- **Default Column Definitions:** Similar to Column Definitions, but applies configurations to all columns.
- **Grid Options:** Configure functionality which extends across the entire grid.
- **Grid Events:** Events raised by the grid, typically as a result of user interaction.
- **Value Formatters:** Functions used for basic text formatting
- **Cell Renderers:** Add your own components to cells

## Next Steps

Browse our guides to dive into specific features of the grid:

- [Theming & Styling](https://www.ag-grid.com/archive/36.1.0/react-data-grid/theming/)
- [Testing](https://www.ag-grid.com/archive/36.1.0/react-data-grid/testing/)
- [Security](https://www.ag-grid.com/archive/36.1.0/react-data-grid/security/)
