Data Grid Examples
Following are three example implementations of the 설계 패턴 for grid 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.
유사한 예는 다음과 같습니다:
- 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
Date | Type | Description | Amount | Balance |
---|---|---|---|---|
01-Jan-16 | Deposit | Cash Deposit | $1,000,000.00 | $1,000,000.00 |
02-Jan-16 | Debit | Down Town Grocery | $250.00 | $999,750.00 |
03-Jan-16 | Debit | Hot Coffee | $9.00 | $999,741.00 |
04-Jan-16 | Debit | The Filling Station | $88.00 | $999,653.00 |
05-Jan-16 | Debit | Tinker's Hardware | $3,421.00 | $996,232.00 |
06-Jan-16 | Debit | Cutey's Salon | $700.00 | $995,532.00 |
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
Date | Type | Description | Category | Amount | Balance |
---|---|---|---|---|---|
01-Jan-16 | Deposit |
|
$1,000,000.00 | $1,000,000.00 | |
02-Jan-16 | Debit |
|
$250.00 | $999,750.00 | |
03-Jan-16 | Debit |
|
$9.00 | $999,741.00 | |
04-Jan-16 | Debit |
|
$88.00 | $999,653.00 | |
05-Jan-16 | Debit |
|
$3,421.00 | $996,232.00 | |
06-Jan-16 | Debit |
|
$700.00 | $995,532.00 | |
07-Jan-16 | Debit |
|
$41.00 | $995,491.00 |
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
Date | Type | Description | Category | Amount | Balance |
---|---|---|---|---|---|
01-Jan-16 | Deposit | Cash Deposit | Income | $1,000,000.00 | $1,000,000.00 |
02-Jan-16 | Debit | Down Town Grocery | Groceries | $250.00 | $999,750.00 |
03-Jan-16 | Debit | Hot Coffee | Dining Out | $9.00 | $999,741.00 |
04-Jan-16 | Debit | The Filling Station | Auto | $88.00 | $999,653.00 |
05-Jan-16 | Debit | Tinker's Hardware | Household | $3,421.00 | $996,232.00 |
06-Jan-16 | Debit | Cutey's Salon | Beauty | $700.00 | $995,532.00 |
07-Jan-16 | Debit | My Chocolate Shop | Dining Out | $41.00 | $995,491.00 |
08-Jan-16 | Debit | Who's Cook'n | Dining Out | $150.00 | $995,341.00 |
09-Jan-16 | Debit | Dmuddy Paws | Pet | $100.00 | $995,241.00 |
10-Jan-16 | Debit | West End Bikes | Recreation | $6,420.00 | $988,821.00 |
11-Jan-16 | Debit | Pay More Cars | Auto | $431,323.00 | $557,498.00 |
12-Jan-16 | Debit | The Interior Shop | Household | $142,334.00 | $415,164.00 |
13-Jan-16 | Debit | Adventure Guys | Recreation | $88,424.00 | $326,740.00 |
14-Jan-16 | Debit | Hungry Folks Place | Dining Out | $313.00 | $326,427.00 |
15-Jan-16 | Debit | Horse Play | Recreation | $2,421.00 | $324,006.00 |
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-rowindex
value 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-colindex
value 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.
키보드 지원
키 | 기능 |
---|---|
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, Tabindex 어트리뷰트
역할(role) | 어트리뷰트 | 엘리먼트 | 사용법 |
---|---|---|---|
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와 CSS 소스 코드
- CSS:
- JavaScript:
HTML 소스 코드
Example 1: Minimal Data Grid
Example 2: Sortable Data Grid With Editable Cells
Example 3: Scrollable Data Grid With Column Hiding