in src/draft-components/grid/grid.tsx [164:240]
render() {
const {
columns = [],
description,
editable,
gridType = 'table',
headerActionsMenu,
rowSelection,
selectedRows,
sortedCells = [],
sortedColumn,
sortState,
useApplicationRole
} = this;
const rowSelectionState = this.getSelectionState();
const tableRole = useApplicationRole ? 'application' : gridType;
return <table role={tableRole} aria-roledescription={useApplicationRole ? 'editable data grid' : null} class="grid" aria-labelledby={this.labelledBy} aria-readonly={editable ? null : 'true'}>
{description ? <caption>{description}</caption> : null}
<thead role="rowgroup" class="grid-header">
<tr role="row" class="row">
{rowSelection !== RowSelectionPattern.None ?
<th role="columnheader" aria-labelledby="select-all-header" class={{'checkbox-cell': true, 'indeterminate': rowSelectionState === 'indeterminate'}}>
<span class="visuallyHidden" id="select-all-header">select row</span>
<input
type="checkbox"
aria-label="select all rows"
checked={!!rowSelectionState}
ref={(el) => {
if (rowSelectionState === 'indeterminate') {
el.indeterminate = true;
}
}}
onChange={(event) => this.onSelectAll((event.target as HTMLInputElement).checked)} />
<span class="selection-indicator"></span>
</th>
: null}
{columns.map((column, index) => {
return renderHeaderCell({
column,
colIndex: index,
actionsMenu: headerActionsMenu,
isSortedColumn: sortedColumn === index,
sortDirection: sortState,
onSort: this.onSortColumn.bind(this),
onFilter: this.onFilterInput.bind(this)
});
})}
</tr>
</thead>
<tbody role="rowgroup" class="grid-body" onKeyDown={this.onCellKeydown.bind(this)}>
{sortedCells.map((cells = [], index) => {
const isSelected = !!selectedRows.get(cells);
let rowOptions: RowOptions = {
cells,
index,
isSelected,
selection: rowSelection,
renderCell: this.renderCell.bind(this),
renderCheckboxCell: this.renderCheckboxCell.bind(this),
onSelectionChange: this.onRowSelect.bind(this)
};
if (this.rowSelection === RowSelectionPattern.Aria) {
const isActiveRow = this.activeCell[1] === index;
rowOptions = {
...rowOptions,
isActiveRow,
setFocusRef: (el) => this.focusRef = el,
onRowKeyDown: this.onRowKeyDown.bind(this)
}
}
return renderRow(rowOptions);
})}
</tbody>
</table>;
}