---
title: DataGrid
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, FigmaEmbed, PropsTable, TokensTable } from '../../src/components'
import { DataGrid } from '@telus-uds/components-community'
import { DataGrid as DataGridDocs } from 'docs/@telus-uds/components-community'
import AvailableOnWebOnly from '../../partials/_platform-considerations-web-only.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# DataGrid

<LibraryInfo
  packageType="Web Component"
  packageName="components-community.datagrid"
  figmaLink="https://www.figma.com/design/hha8eldWQIf1mZOZR6IGIG/UDS-TELUS-Casa-Components?node-id=7232-15286&node-type=section&t=D26EujD1DjIXaoeh-0"
/>

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={false}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' },
    { key: 'email', label: 'Email', width: '300px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john.doe@example.com'
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane.smith@example.com'
    }
  ]}
/>
```

## Introduction

Use DataGrid to display tabular data of dynamic number of columns

```jsx
import { DataGrid } from '@telus-uds/components-community.datagrid'
```

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

This feature enhancement aims to provide an advanced DataGrid with features beyond what a simple Table can offer. The following enhancements are proposed:

- Expandable Rows:
  - Add the ability to click on a caret icon to expand a row and show more details.
  - The expanded row should collapse when the caret icon is clicked again.
  - The expanded row can contain mixed content laid out using components such as Box and StackView, and may include other tables nested inside the rows, form controls and buttons, and other UI components.
- Row Selection:
  - Introduce checkboxes for each row to allow users to select one or multiple rows.
  - Include an `All` checkbox in the table header to select all rows if desired.
  - Provide a way to perform bulk actions on the selected rows.
- Fixed Height Tables:
  - Enable the rows to scroll within a fixed height table.
  - The table header should remain fixed while the rows scroll.
- Visual Enhancements
  - Rows of tables inside the expansion panel should have the option to turn row bottom margin divider lines off for visual simplicity
  - The Cell subcomponent will be modified to be able to span multiple columns with properties render `colspan` attributes in the output cell elements

### Checkboxes

Pass `showCheckbox=true` prop to the component to diplay checkboxes for each row.

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' },
    { key: 'email', label: 'Email', width: '300px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john.doe@example.com',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <DataGrid
            showCheckbox={false}
            tokens={{
              expandedRowPadding: '100px',
              expandedRowBackGround: '#F8F7F8',
              firstColWidth: '50px',
              iconSpacing: '20px',
              hideRowBottomBorder: 0
            }}
            columns={[
              { key: 'time', label: 'Time', width: '50px' },
              { key: 'total', label: 'Total', width: '50px' },
              { key: 'network', label: 'Network', width: '50px' },
              { key: 'speed', label: 'Reduced Speed', width: '50px' }
            ]}
            rows={[
              { id: 1, time: '8.39pm', total: '1100.00 MB', network: '5G', speed: 'No' },
              { id: 2, time: '8.29pm', total: '22.99 MB', network: '5G', speed: 'No' },
              { id: 3, time: '8.15pm', total: '0.02 MB', network: 'LTE', speed: 'Yes' },
              { id: 4, time: '6.30pm', total: '0.09 MB', network: 'LTE', speed: 'Yes' }
            ]}
          />
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane.smith@example.com'
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20',
      email: 'janus.chopper@example.com'
    },
    {
      id: 4,
      firstName: 'January',
      lastName: 'Smith',
      age: '28',
      email: 'january.smith@example.com'
    }
  ]}
/>
```

### Expanded content

Each row has the opportunity to display additional data via the `expandedRowChildComponent` object within the `rows` prop; the `expandedRowChildComponent`
provides two values:

- `displayOnLoad` key: set this to `true` to automatically display the expanded content when the grid is mounted.
- `component` key: this can be set to any React component and will be displayed as-is; the only possible configuration is horizontal
  alignment of the expanded row.

### Expanded content alignment

Expanded content can be horizontally aligned via the `theme` file or via the `tokens` props; the code used [css' `justify-content`](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content).

- Via Theme
  - Pass the correct value to the `expandedContentAlignment` token
- Via Tokens props
  - Pass `tokens={{expandedContentAlignment: [value]}}` prop to the component

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    checkboxChevronIconGap: 10,
    iconSpacing: '20px',
    expandedContentAlignment: 'center',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <ExpandCollapse>
            {(expandProps) => (
              <StackView space={3}>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="first"
                  control={<Typography>First panel</Typography>}
                >
                  <Typography>Some content within the first panel</Typography>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="second"
                  control={<Typography>Second panel</Typography>}
                >
                  <Card>
                    <Typography block variant={{ size: 'h2' }}>
                      Connecting with the community
                    </Typography>
                    <Box top={4}>
                      <Typography>
                        Card width expands based on the container. Card height expands based on
                        content.
                      </Typography>
                      <Box top={4}>
                        <Button onPress={null} variant={{ priority: 'high', width: 'full' }}>
                          Sign up
                        </Button>
                      </Box>
                    </Box>
                  </Card>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel panelId="third" content>
                  <Typography>Some non-expandable content</Typography>
                </ExpandCollapse.Panel>
              </StackView>
            )}
          </ExpandCollapse>
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <Typography>
            <Typography block variant={{ size: 'display2' }}>
              Hey World!
            </Typography>
            <Typography block variant={{ size: 'large' }}>
              Paragraphing
            </Typography>
          </Typography>
        )
      }
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20'
    }
  ]}
/>
```

### Chevron toggle with custom business logic

The chevron icon provides more than basic expand/collapse functionality; you can implement custom business logic by passing an `onChevronToggle` function to the `expandedRowChildComponent` prop.

#### Function parameters

The onChevronToggle function receives:

- _data_: Current internal state of the datagrid component.
- _rowId_: Row identifier _(either the id key or groupname + id concatenation)._

#### Return value

_Important:_ The function must return the same data structure to prevent unintended behavior.

#### Example: Single Row Expansion

The following example closes all other expanded rows, keeping only the current row open:

```
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      expandedRowChildComponent: {
        displayOnLoad: false,
        onChevronToggle: (data, rowId) => {
          const changedData = data.map((row) => {
            const newRow = { ...row }
            if (newRow.id !== rowId) {
              newRow.isExpandedRowOpen = false
            }
            return newRow
          })

          return changedData
        },
        component: (...)
      }
    }
```

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    expandedContentAlignment: 'center',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      expandedRowChildComponent: {
        displayOnLoad: false,
        onChevronToggle: (data, rowId) => {
          const changedData = data.map((row) => {
            const newRow = { ...row }
            if (newRow.id !== rowId) {
              newRow.isExpandedRowOpen = false
            }
            return newRow
          })

          return changedData
        },
        component: (
          <ExpandCollapse>
            {(expandProps) => (
              <StackView space={3}>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="first"
                  control={<Typography>First panel</Typography>}
                >
                  <Typography>Some content within the first panel</Typography>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="second"
                  control={<Typography>Second panel</Typography>}
                >
                  <Card>
                    <Typography block variant={{ size: 'h2' }}>
                      Connecting with the community
                    </Typography>
                    <Box top={4}>
                      <Typography>
                        Card width expands based on the container. Card height expands based on
                        content.
                      </Typography>
                      <Box top={4}>
                        <Button onPress={null} variant={{ priority: 'high', width: 'full' }}>
                          Sign up
                        </Button>
                      </Box>
                    </Box>
                  </Card>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel panelId="third" content>
                  <Typography>Some non-expandable content</Typography>
                </ExpandCollapse.Panel>
              </StackView>
            )}
          </ExpandCollapse>
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      expandedRowChildComponent: {
        displayOnLoad: false,
        onChevronToggle: (data, rowId) => {
          const changedData = data.map((row) => {
            const newRow = { ...row }
            if (newRow.id !== rowId) {
              newRow.isExpandedRowOpen = false
            }
            return newRow
          })

          return changedData
        },
        component: (
          <Typography>
            <Typography block variant={{ size: 'display2' }}>
              Hey World!
            </Typography>
            <Typography block variant={{ size: 'large' }}>
              Paragraphing
            </Typography>
          </Typography>
        )
      }
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20',
      expandedRowChildComponent: {
        displayOnLoad: false,
        onChevronToggle: (data, rowId) => {
          const changedData = data.map((row) => {
            const newRow = { ...row }
            if (newRow.id !== rowId) {
              newRow.isExpandedRowOpen = false
            }
            return newRow
          })

          return changedData
        },
        component: (
          <ExpandCollapse>
            {(expandProps) => (
              <StackView space={3}>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="first"
                  control={<Typography>First panel</Typography>}
                >
                  <Typography>Some content within the first panel</Typography>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="second"
                  control={<Typography>Second panel</Typography>}
                >
                  <Card>
                    <Typography block variant={{ size: 'h2' }}>
                      Connecting with the community
                    </Typography>
                    <Box top={4}>
                      <Typography>
                        Card width expands based on the container. Card height expands based on
                        content.
                      </Typography>
                      <Box top={4}>
                        <Button onPress={null} variant={{ priority: 'high', width: 'full' }}>
                          Sign up
                        </Button>
                      </Box>
                    </Box>
                  </Card>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel panelId="third" content>
                  <Typography>Some non-expandable content</Typography>
                </ExpandCollapse.Panel>
              </StackView>
            )}
          </ExpandCollapse>
        )
      }
    }
  ]}
/>
```

### Row controlled checkboxes

The checkbox on each row is now controlled by the data, which is controlled by the consuming app.

- to hide checkbox for a row, pass `hideCheckbox: true` as part of the data for the row
- All the props available to the [checkbox](https://www.telus.com/universal-design-system/components/casa/Checkbox) can be passed to the `checkBoxProps` object in the row.

```
rows={[{
  ...,
  hideCheckbox: true,
  checkBoxProps: {
    inactive: true,
    checked: false,
    name: 'row_1',
    value: 'value',
    onChange: (e) => {}
}
}]}
```

- Keep in mind the following expected user experience
  - Toggling header checkbox only affects row checkboxes that are visible and enabled _(i.e. rows without checkboxes are not impacted)_.
  - If no rows has checkboxes, the header checkbox will be hidden
  - If all the rows have disabled checkboxes, the header checkbox will be disabled
  - If at least a row has checkboxes enabled, the header checkbox will be enabled and displayed.
  - A hidden checkbox `hideCheckbox: true` should have these properties set _(the component doesn't automatically reset them to prevent inadvertent results in certain situations)_
    - `inactive: true` - a hidden checkbox does not need to be active
    - `checked: false` - a hidden checkbox does not need to be checked

```jsx live
<DataGrid
  showCheckbox={true}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' },
    { key: 'email', label: 'Email', width: '300px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john.doe@example.com',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <Typography>
            <Typography block variant={{ size: 'display2' }}>
              Hey World!
            </Typography>
            <Typography block variant={{ size: 'large' }}>
              Paragraphing
            </Typography>
          </Typography>
        )
      },
      hideCheckbox: true,
      checkBoxProps: {
        inactive: true,
        checked: false,
        name: 'row_1',
        value: 'value',
        onChange: (e) => console.log(e, 'I just got clicked ')
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane.smith@example.com',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <Typography>
            <Typography block variant={{ size: 'display2' }}>
              Hey World!
            </Typography>
            <Typography block variant={{ size: 'large' }}>
              Paragraphing
            </Typography>
          </Typography>
        )
      },
      hideCheckbox: false,
      checkBoxProps: {
        inactive: false,
        checked: true,
        name: 'row_2',
        value: 'value 2',
        onChange: () => console.log('I just got clicked ')
      }
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20',
      email: 'janus.chopper@example.com',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <Typography>
            <Typography block variant={{ size: 'display2' }}>
              Hey World!
            </Typography>
            <Typography block variant={{ size: 'large' }}>
              Paragraphing
            </Typography>
          </Typography>
        )
      },
      hideCheckbox: false,
      checkBoxProps: {
        inactive: false,
        checked: false,
        error: true,
        name: 'row_3',
        value: 'value 3',
        onChange: (e) => console.log(e, 'I just got clicked ')
      }
    },
    {
      id: 4,
      firstName: 'January',
      lastName: 'Smith',
      age: '28',
      email: 'january.smith@example.com',
      hideCheckbox: false,
      checkBoxProps: {
        inactive: false,
        checked: false,
        value: 'value 4',
        onChange: (e) => console.log('I just got clicked ')
      }
    }
  ]}
/>
```

### Text alignment

#### Header

The grid header content can now be text-aligned; just pass additional key `textAlign` in the `columns` prop and set
its value to any of `start|center|end`.

```
columns: [
  {
    key: 'lastName',
    label: 'Last Name',
    width: '150px',
    textAlign: 'center'
  },
  ...rest
]
```

#### Body

Following the _design principle of data-agnostic content_, the grid's body doesn't directly have a text alignment; however, it now
exposes an optional function `displayedComponent` key in the `columns` prop that allows the consumer to pass the component
to be displayed for all the rows in that column.

```
columns: [
  {
    key: 'lastName',
    label: 'Last Name',
    width: '150px',
    textAlign: 'center',
    displayedComponent: (children) => (
      <Typography align="center" block variant={{ size: 'small' }}>
        {children}
      </Typography>
    )
  },
  ...rest
]
```

With this approach, the consumer can simply pass in any component _(images, text, etc.)_ along with their desired attributes;
below is an example

- the 2nd column utilizes a center-aligned Typography component
- the 3rd column utilizes a right-aligned Typography component

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    checkboxChevronIconGap: 0,
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    {
      key: 'firstName',
      label: 'First Name',
      width: '50px'
    },
    {
      key: 'lastName',
      label: 'Last Name',
      width: '150px',
      textAlign: 'center',
      displayedComponent: (children) => (
        <Typography align="center" block variant={{ size: 'small' }}>
          {children}
        </Typography>
      )
    },
    {
      key: 'age',
      label: 'Age',
      width: '100px',
      textAlign: 'end',
      displayedComponent: (children) => (
        <Typography align="right" block variant={{ size: 'small' }}>
          {children}
        </Typography>
      )
    }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john.doe@example.com',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <DataGrid
            showCheckbox={false}
            tokens={{
              expandedRowPadding: '100px',
              expandedRowBackGround: '#F8F7F8',
              firstColWidth: '50px',
              iconSpacing: '20px',
              hideRowBottomBorder: 0
            }}
            columns={[
              { key: 'time', label: 'Time', width: '50px' },
              { key: 'total', label: 'Total', width: '50px' },
              { key: 'network', label: 'Network', width: '50px' },
              { key: 'speed', label: 'Reduced Speed', width: '50px' }
            ]}
            rows={[
              { id: 1, time: '8.39pm', total: '1100.00 MB', network: '5G', speed: 'No' },
              { id: 2, time: '8.29pm', total: '22.99 MB', network: '5G', speed: 'No' },
              { id: 3, time: '8.15pm', total: '0.02 MB', network: 'LTE', speed: 'Yes' },
              { id: 4, time: '6.30pm', total: '0.09 MB', network: 'LTE', speed: 'Yes' }
            ]}
          />
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane.smith@example.com'
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20',
      email: 'janus.chopper@example.com'
    },
    {
      id: 4,
      firstName: 'January',
      lastName: 'Smith',
      age: '28',
      email: 'january.smith@example.com'
    }
  ]}
/>
```

### Sortable

Only non-grouped data can be sorted by setting prop `isSortable` to `true`; consult the [Columns Prop](#columns-prop)
for more technical details.

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  isSortable={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    {
      key: 'firstName',
      label: 'First Name',
      width: '50px',
      isSortable: true,
      dataType: 'string',
      fn: null
    },
    {
      key: 'lastName',
      label: 'Last Name',
      width: '150px',
      isSortable: true,
      dataType: 'string',
      fn: null
    },
    { key: 'age', label: 'Age', width: '100px', isSortable: true, dataType: 'number', fn: null }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john.doe@example.com',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <DataGrid
            showCheckbox={false}
            tokens={{
              expandedRowPadding: '100px',
              expandedRowBackGround: '#F8F7F8',
              firstColWidth: '50px',
              iconSpacing: '20px',
              hideRowBottomBorder: 0
            }}
            columns={[
              { key: 'time', label: 'Time', width: '50px' },
              { key: 'total', label: 'Total', width: '50px' },
              { key: 'network', label: 'Network', width: '50px' },
              { key: 'speed', label: 'Reduced Speed', width: '50px' }
            ]}
            rows={[
              { id: 1, time: '8.39pm', total: '1100.00 MB', network: '5G', speed: 'No' },
              { id: 2, time: '8.29pm', total: '22.99 MB', network: '5G', speed: 'No' },
              { id: 3, time: '8.15pm', total: '0.02 MB', network: 'LTE', speed: 'Yes' },
              { id: 4, time: '6.30pm', total: '0.09 MB', network: 'LTE', speed: 'Yes' }
            ]}
          />
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane.smith@example.com'
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20',
      email: 'janus.chopper@example.com'
    },
    {
      id: 4,
      firstName: 'January',
      lastName: 'Smith',
      age: '28',
      email: 'january.smith@example.com'
    }
  ]}
/>
```

### Turn off row border

The row border for the data can be turned off from the theme or via a token prop.

- Via Variant
  - Pass the variant `variant={{ no_row_border: true }}` prop to the component
- Via Theme
  - Pass `1` or `0` to the token `hideRowBottomBorder` to hide or display the borders.
- Via Tokens props
  - Pass `tokens={{hideRowBottomBorder: 1}}` to hide the borders
  - Pass `tokens={{hideRowBottomBorder: 0}}` to display the borders

```jsx live
<DataGrid
  variant={{ no_row_border: true }}
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <DataGrid
            showCheckbox={false}
            tokens={{
              expandedRowPadding: '100px',
              expandedRowBackGround: '#F8F7F8',
              firstColWidth: '50px',
              iconSpacing: '20px'
            }}
            columns={[
              { key: 'time', label: 'Time', width: '50px' },
              { key: 'total', label: 'Total', width: '50px' },
              { key: 'network', label: 'Network', width: '50px' },
              { key: 'speed', label: 'Reduced Speed', width: '50px' }
            ]}
            rows={[
              { id: 1, time: '8.39pm', total: '1100.00 MB', network: '5G', speed: 'No' },
              { id: 2, time: '8.29pm', total: '22.99 MB', network: '5G', speed: 'No' },
              { id: 3, time: '8.15pm', total: '0.02 MB', network: 'LTE', speed: 'Yes' },
              { id: 4, time: '6.30pm', total: '0.09 MB', network: 'LTE', speed: 'Yes' }
            ]}
          />
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28'
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20'
    }
  ]}
/>
```

### Turn off row border on expanded content

Nested DataGrids can have different configurations; in the below example, the expanded DataGrid does not have any row border.

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <DataGrid
            variant={{ no_row_border: true }}
            showCheckbox={false}
            tokens={{
              expandedRowPadding: '100px',
              expandedRowBackGround: '#F8F7F8',
              firstColWidth: '50px',
              iconSpacing: '20px'
            }}
            columns={[
              { key: 'time', label: 'Time', width: '50px' },
              { key: 'total', label: 'Total', width: '50px' },
              { key: 'network', label: 'Network', width: '50px' },
              { key: 'speed', label: 'Reduced Speed', width: '50px' }
            ]}
            rows={[
              { id: 1, time: '8.39pm', total: '1100.00 MB', network: '5G', speed: 'No' },
              { id: 2, time: '8.29pm', total: '22.99 MB', network: '5G', speed: 'No' },
              { id: 3, time: '8.15pm', total: '0.02 MB', network: 'LTE', speed: 'Yes' },
              { id: 4, time: '6.30pm', total: '0.09 MB', network: 'LTE', speed: 'Yes' }
            ]}
          />
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28'
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20'
    }
  ]}
/>
```

### Different custom expanded content per row

Each data row can display a different component when it expands

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <ExpandCollapse>
            {(expandProps) => (
              <StackView space={3}>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="first"
                  control={<Typography>First panel</Typography>}
                >
                  <Typography>Some content within the first panel</Typography>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel
                  {...expandProps}
                  panelId="second"
                  control={<Typography>Second panel</Typography>}
                >
                  <Card>
                    <Typography block variant={{ size: 'h2' }}>
                      Connecting with the community
                    </Typography>
                    <Box top={4}>
                      <Typography>
                        Card width expands based on the container. Card height expands based on
                        content.
                      </Typography>
                      <Box top={4}>
                        <Button onPress={null} variant={{ priority: 'high', width: 'full' }}>
                          Sign up
                        </Button>
                      </Box>
                    </Box>
                  </Card>
                </ExpandCollapse.Panel>
                <ExpandCollapse.Panel panelId="third" content>
                  <Typography>Some non-expandable content</Typography>
                </ExpandCollapse.Panel>
              </StackView>
            )}
          </ExpandCollapse>
        )
      }
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      expandedRowChildComponent: {
        displayOnLoad: false,
        component: (
          <Typography>
            <Typography block variant={{ size: 'display2' }}>
              Hey World!
            </Typography>
            <Typography block variant={{ size: 'large' }}>
              Paragraphing
            </Typography>
          </Typography>
        )
      }
    },
    {
      id: 3,
      firstName: 'Janus',
      lastName: 'Chopper',
      age: '20'
    }
  ]}
/>
```

### Grouped data with sticky header

Grouped data can be passed to the DataGrid via the `groupedRows` prop.

- `groupedRows` prop is required for grouped data
  - The `key` values _(`group_1, group_2, etc`)_ in the sample data MUST be a valid JavaScript variable identifier.
  - The `name` value is required if the `groupHeaderComponent` is not provided; this will be used as the group subheader if a custom component is not passed
  - A custom component to display for the group subheader can be passed via the `groupHeaderComponent` key
  - `data` array must be passed, with the number of columns matching the those in the `columns` prop.
- `rows` prop is not required for grouped data

```jsx live
<DataGrid
  title="DataGrid"
  showCheckbox={true}
  isHeaderSticky={true}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' }
  ]}
  groupedRows={[
    {
      key: 'group_1',
      name: 'Group 1',
      groupHeaderComponent: (
        <Typography block variant={{ size: 'display2' }}>
          Group 1
        </Typography>
      ),
      data: [
        {
          id: 1,
          firstName: 'John 1',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            displayOnLoad: true,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  Hey World!
                </Typography>
                <Typography block variant={{ size: 'large' }}>
                  Paragraphing
                </Typography>
              </Typography>
            )
          }
        },
        {
          id: 2,
          firstName: 'Jane 2',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        }
      ]
    },
    {
      key: 'group_2',
      name: 'Group 2',
      groupHeaderComponent: null,
      data: [
        {
          id: 1,
          firstName: 'John 3',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        },
        {
          id: 2,
          firstName: 'Jane 4',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        }
      ]
    },
    {
      key: 'group_3',
      name: 'Group 3',
      groupHeaderComponent: (
        <Typography block variant={{ size: 'h1' }}>
          Eccentric Group
        </Typography>
      ),
      data: [
        {
          id: 1,
          firstName: 'John 5',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        },
        {
          id: 2,
          firstName: 'Jane 6',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        }
      ]
    },
    {
      key: 'group_4',
      name: 'Group 4',
      groupHeaderComponent: null,
      data: [
        {
          id: 1,
          firstName: 'John 7',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        },
        {
          id: 2,
          firstName: 'Jane 8',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            displayOnLoad: false,
            component: (
              <Typography>
                <Typography block variant={{ size: 'display2' }}>
                  I'm a custom component provided by the consuming app
                </Typography>
              </Typography>
            )
          }
        }
      ]
    }
  ]}
/>
```

### Sticky header

Pass `isHeaderSticky=true` prop to the component to make the header sticky at the top

```jsx live
<DataGrid
  title="DataGrid"
  isHeaderSticky={true}
  showCheckbox={false}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' },
    { key: 'email', label: 'Email', width: '300px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john1.doe@example.com'
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane1.smith@example.com'
    },
    {
      id: 3,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john2.doe@example.com'
    },
    {
      id: 4,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane2.smith@example.com'
    },
    {
      id: 5,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john3.doe@example.com'
    },
    {
      id: 6,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane3.smith@example.com'
    },
    {
      id: 7,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john4.doe@example.com'
    },
    {
      id: 8,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane4.smith@example.com'
    },
    {
      id: 9,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john5.doe@example.com'
    },
    {
      id: 10,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane5.smith@example.com'
    },
    {
      id: 11,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john6.doe@example.com'
    },
    {
      id: 12,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane6.smith@example.com'
    },
    {
      id: 13,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john7.doe@example.com'
    },
    {
      id: 14,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane7.smith@example.com'
    },
    {
      id: 15,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john8.doe@example.com'
    },
    {
      id: 16,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane8.smith@example.com'
    },
    {
      id: 17,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john9.doe@example.com'
    },
    {
      id: 18,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane9.smith@example.com'
    },
    {
      id: 19,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john10.doe@example.com'
    },
    {
      id: 20,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane10.smith@example.com'
    }
  ]}
/>
```

### Hidden header

Pass `isHeaderVisible=false` prop to the component to hide the header

```jsx live
<DataGrid
  title="DataGrid"
  isHeaderVisible={false}
  showCheckbox={false}
  tokens={{
    expandedRowPadding: '100px',
    expandedRowBackGround: '#F8F7F8',
    firstColWidth: '50px',
    iconSpacing: '20px',
    maxHeight: '500'
  }}
  columns={[
    { key: 'firstName', label: 'First Name', width: '50px' },
    { key: 'lastName', label: 'Last Name', width: '150px' },
    { key: 'age', label: 'Age', width: '100px' },
    { key: 'email', label: 'Email', width: '300px' }
  ]}
  rows={[
    {
      id: 1,
      firstName: 'John',
      lastName: 'Doe',
      age: '35',
      email: 'john.doe@example.com'
    },
    {
      id: 2,
      firstName: 'Jane',
      lastName: 'Smith',
      age: '28',
      email: 'jane.smith@example.com'
    }
  ]}
/>
```

### Accessibility

### Platform considerations

<AvailableOnWebOnly />

:::danger

**Breaking Change: Removed third-party scrollbar library**

The third-party library previously used for the "always-visible-scrollbar" feature has been removed due to incompatibility with the new sticky-header implementation. This is a breaking change from v1.3.4 and necessitates a major version release (2.x).

Alternative system-level scrollbar settings: You can still achieve always-visible scrollbars through your system settings:

- Mac: Settings > Appearance > Show scroll bars > Select "Always"
- Windows: Settings > Accessibility > Visual effects > Always show scrollbars > On

:::

## Props

### DataGrid

DataGrid can be used directly by passing values to any of its props as outlined below:

<PropsTable web={DataGridDocs} />

### Columns Prop

The `columns` prop is an array of objects containing the following keys

- `key`: unique required `string` prop to identify a column; string must be a valid JavaScript variable
- `label`: required `string` prop for the name to be displayed for the column
- `width`: optional `string` prop for the column width in px _(e.g. `50px`)_
- `dataType`: optional `string` prop for sorting purposes.
  - Accepted values are `string` and `number`
- `isSortable`: optional `boolean` prop to determine if a column should be sortable; if set to `true`, `dataType` value is required
  - A `isSortable` prop set to `true` must also be passed to the Datagrid component.
- `fn`: optional `function` prop for custom sorting a column; the function accepts the following parameters
  - `column` - current `column` being processed
  - `data` - the current `rows` state within the grid
  - `dataUpdater` - function to update the `rows` state within the grid
  - `columnsData` - the current `columns` state within the grid
  - `columnsUpdater` - function to update the `columns` state within the grid
- `textAlign`: optional `string` prop for text alignment of the header
  - Accepted values are `start`, `center`, or `end`
- `displayedComponent`: optional `function` prop for custom component to be displayed for the row
  - parameter for the function is the content to be displayed.
  - the function will be used for all rows on this column.

A sample is provided below:

```
columns = [
  { key: 'time', label: 'Time', width: '50px' },
  { key: 'total', label: 'Total', width: '50px' },
  { key: 'network', label: 'Network', width: '50px' },
  { key: 'speed', label: 'Reduced Speed', width: '50px' }
]
```

### Rows Prop

This is to display rows of data without any grouping.

The `rows` prop is an array of objects containing the following keys

- `id`: a unique integer to identify the data in a row; this is a required key
- Keys matching each of the `key` objects in the `columns` prop
  - For example, if the `columns` prop has an array of 4 objects _(with 4 keys)_, each of the 4 keys must become a key in each
    object of the row
- `expandedRowChildComponent`: Optional prop to display additional content on row expansion; review the sections on row expansion for sample usage.
- `hideCheckbox`: Optional boolean prop to toggle the display of checkbox for a row
- `checkBoxProps`: Optional object prop to pass to the checkboxes; available props are accessible on [UDS Checkbox](https://www.telus.com/universal-design-system/components/casa/checkbox#props)

A sample is provided below:

```
rows = [
  {
    id: 1,
    time: '8.39pm',
    total: '1100.00 MB',
    network: '5G',
    speed: 'No'
  },
  {
    id: 2,
    time: '8.29pm',
    total: '22.99 MB',
    network: '5G',
    speed: 'No'
  },
  {
    id: 3,
    time: '8.15pm',
    total: '0.02 MB',
    network: 'LTE',
    speed: 'Yes'
  },
  {
    id: 4,
    time: '6.30pm',
    total: '0.09 MB',
    network: 'LTE',
    speed: 'Yes'
  }
]
```

### GroupedRows Prop

This is to display rows of grouped data.

> Only one of `rows` or `groupedRows` prop must be provided; the grid defaults to `rows`

The `groupedRows` prop is an array of objects containing the following keys

- `key`: required `string` prop to uniquely identify a set/group of data
- `name`: required `string` prop to be displayed for a group of data
- `groupHeaderComponent`: optional React `node` prop to be displayed for a group of data
  - the component defaults to `name` prop whenever this prop is unavailable.
- `data`: required `array` prop of data to be displayed for this group
  - this structure for this data is the same as the structure of the `rows` prop.

A sample is provided below:

```
  groupedRows = [
    {
      key: 'group_1',
      name: 'Group 1',
      groupHeaderComponent: GroupHeaderComponent,
      data: [
        {
          id: 1,
          firstName: 'John 1',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            component: ExpandComponent,
            displayOnLoad: true
          }
        },
        {
          id: 2,
          firstName: 'Jane 2',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            component: TypographyComponent,
            displayOnLoad: false
          }
        }
      ]
    },
    {
      key: 'group_2',
      name: 'Group 2',
      groupHeaderComponent: null,
      data: [
        {
          id: 1,
          firstName: 'John 3',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            component: ExpandComponent,
            displayOnLoad: false
          }
        },
        {
          id: 2,
          firstName: 'Jane 4',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            component: TypographyComponent,
            displayOnLoad: false
          }
        }
      ]
    },
    {
      key: 'group_3',
      name: 'Group 3',
      groupHeaderComponent: (
        <Typography block variant={{ size: 'h1' }}>
          Eccentric Group
        </Typography>
      ),
      data: [
        {
          id: 1,
          firstName: 'John 5',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            component: ExpandComponent,
            displayOnLoad: false
          }
        },
        {
          id: 2,
          firstName: 'Jane 6',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            component: TypographyComponent,
            displayOnLoad: false
          }
        }
      ]
    },
    {
      key: 'group_4',
      name: 'Group 4',
      groupHeaderComponent: null,
      data: [
        {
          id: 1,
          firstName: 'John 7',
          lastName: 'Doe',
          age: '35',
          email: 'john.doe@example.com',
          expandedRowChildComponent: {
            component: ExpandComponent,
            displayOnLoad: false
          }
        },
        {
          id: 2,
          firstName: 'Jane 8',
          lastName: 'Smith',
          age: '28',
          email: 'jane.smith@example.com',
          expandedRowChildComponent: {
            component: TypographyComponent,
            displayOnLoad: false
          }
        }
      ]
    }
  ]
```

#### Alternatively, a customized DataGrid solution can be created by assembling each piece of the DataGrid structure as outlined below:

### DataGrid.Table

<PropsTable web={DataGridDocs.Table} />

### DataGrid.Head

<PropsTable web={DataGridDocs.Head} />

### DataGrid.Body

<PropsTable web={DataGridDocs.Body} />

### DataGrid.Row

<PropsTable web={DataGridDocs.Row} />

### DataGrid.Cell

<PropsTable web={DataGridDocs.Cell} />

## Figma

<FigmaEmbed src="https://www.figma.com/design/hha8eldWQIf1mZOZR6IGIG/UDS-TELUS-Casa-Components?node-id=7232-15286&node-type=section&t=D26EujD1DjIXaoeh-0" />

## Tokens

Coming Soon

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="DataGrid" />
