Data Grid Examples
- -About This Example
-- Following are three example implementations of the Grid Pattern that demonstrate the keyboard interactions and ARIA features that enable accessible, interactive presentation of tabular information. - Each of the following three grids presents a set of financial transactions. - The first is a simple grid with minimum ARIA markup and keyboard support. - The second and third implementations add advanced features, such as content editing, sort, scroll, and show/hide. -
-Similar examples include:
--
-
- Layout Grid Examples: Three example implementations of grids that are used to lay out widgets, including a collection of navigation links, a message recipients list, and a set of search results. -
- Advanced Data Grid Example: Example of a grid with behaviors and features similar to a typical spreadsheet, including cell and row selection. -
Examples
-Example 1: Minimal Data Grid
-Transactions January 1 through January 6
Notes
--
-
- Data cells can be focused using standard navigation keys, including directional arrows, Home, End, Control + Home, and Control + End. -
- The Page Down and Page Up keys are not supported since such scroll-like functions are not useful with so few rows. -
- The links can be activated with the keyboard when focused. -
- - Since the header cells do not provide any functionality, they are not focusable. - Screen reader users are still aware of their presence because row and column headers are announced by screen readers during navigation. - And, they are also navigable when using a screen reader's reading or browsing mode. - -
Example 2: Sortable Data Grid With Editable Cells
-Transactions January 1 through January 7
Notes
--
-
- The navigation keys and functions are the same as example 1 except that the column headers are focusable because the date and amount columns provide sort functionality. -
- A description may be edited by activating the cell. -
- A category may be changed by using the category popup menu. -
Example 3: Scrollable Data Grid With Column Hiding
-Transactions for January 1 through January 15
Notes
--
-
- In addition to the navigation keys supported in examples 1 and 2, Page Down and Page Up scroll the grid. -
- As navigating up or down scrolls the visible set of rows, the
aria-rowindexvalue of the row containing the focus informs the screen reader of the number of that row within the total set of rows.
- - Activating the "Hide Type and Category" button hides the type and category columns. -
-
- The
aria-colindexvalue on a cell informs screen readers of the position of that cell within the row. - When one or more columns are hidden, screen reader users can be aware of the hidden columns because those column numbers are not present as users navigate across a row. -
-
Keyboard Support
-| key | -Function | -
|---|---|
| - Right Arrow - | -
-
|
-
| - Left Arrow - | -
-
|
-
| - Down Arrow - | -
-
|
-
| - Up Arrow - | -
-
|
-
| - Page Down - | -
-
|
-
| - Page Up - | -
-
|
-
| - Home - | -moves focus to the first cell in the row that contains focus. | -
| - End - | -moves focus to the last cell in the row that contains focus. | -
| - Control + Home - | -moves focus to the first cell in the first row. | -
| - Control + End - | -moves focus to the last cell in the last row. | -
Role, Property, State, and Tabindex Attributes
-| Role | -Attribute | -Element | -Usage | -
|---|---|---|---|
- grid
- |
- - |
- table
- |
-
-
|
-
| - |
- aria-labelledby="ID_REF"
- |
-
- table
- |
- Refers to the heading element that labels the grid. | -
| - |
- aria-rowcount="16"
- |
-
- table
- |
-
-
|
-
| - |
- aria-colcount="6"
- |
-
- table
- |
-
-
|
-
| - |
- aria-rowindex="INDEX_VALUE"
- |
-
- tr
- |
-
-
|
-
| - |
- aria-sort="ascending"
- |
-
- th
- |
- In example 2, applied when a column is sorted in ascending order. | -
| - |
- aria-sort="descending"
- |
-
- th
- |
- In example 2, applied when a column is sorted in descending order. | -
| - |
- aria-sort="none"
- |
-
- th
- |
- In example 2, applied when a column is sortable but not sorted. | -
| - |
- aria-colindex="INDEX_VALUE"
- |
- th and td |
-
-
|
-
JavaScript and CSS Source Code
--
-
-
- CSS:
-
-
-
- dataGrids.css -
- menuButton.css -
- -
- JavaScript:
-
-
-
- dataGrid.js -
- dataGrids.js -
- menuButton.js -
- utils.js -
-
HTML Source Code
-Example 1: Minimal Data Grid
-To copy the following HTML code, please open it in CodePen.
- -
-
-
-
- Example 2: Sortable Data Grid With Editable Cells
-To copy the following HTML code, please open it in CodePen.
- -
-
-
-
- Example 3: Scrollable Data Grid With Column Hiding
-To copy the following HTML code, please open it in CodePen.
- -
-
-
-
-
-