Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select rows, one by one #18

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
switch to enable rows selection
severo committed Jan 6, 2025
commit aad5288410923a9fdbcb5f7259cb7d97d92c7a17
10 changes: 5 additions & 5 deletions src/HighTable.css
Original file line number Diff line number Diff line change
@@ -109,19 +109,19 @@
.table td:first-child input {
display: none;
}
.table td:first-child:hover span, .table tr.selected td:first-child span {
.table.selectable td:first-child:hover span, .table.selectable tr.selected td:first-child span {
display: none;
}
.table td:first-child:hover input, .table tr.selected td:first-child input {
.table.selectable td:first-child:hover input, .table.selectable tr.selected td:first-child input {
display: inline;
}
.table tr.selected {
.table.selectable tr.selected {
background-color: #e4e4e8;
}
.table tr.selected td {
.table.selectable tr.selected td {
border-right-color: #bbb;
}
.table tr.selected td:first-child {
.table.selectable tr.selected td:first-child {
background-color: #d0d0d8;
}

8 changes: 5 additions & 3 deletions src/HighTable.tsx
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ interface TableProps {
padding?: number // number of padding rows to render outside of the viewport
focus?: boolean // focus table on mount? (default true)
tableControl?: TableControl // control the table from outside
selectable?: boolean // enable row selection (default false)
onDoubleClickCell?: (event: React.MouseEvent, col: number, row: number) => void
onMouseDownCell?: (event: React.MouseEvent, col: number, row: number) => void
onError?: (error: Error) => void
@@ -103,6 +104,7 @@ export default function HighTable({
padding = 20,
focus = true,
tableControl,
selectable = false,
onDoubleClickCell,
onMouseDownCell,
onError = console.error,
@@ -294,7 +296,7 @@ export default function HighTable({
<table
aria-colcount={data.header.length}
aria-rowcount={data.numRows}
className={data.sortable ? 'table sortable' : 'table'}
className={`table${data.sortable ? ' sortable' : ''}${selectable ? ' selectable' : ''}`}
ref={tableRef}
role='grid'
style={{ top: `${offsetTopRef.current}px` }}
@@ -317,8 +319,8 @@ export default function HighTable({
</tr>
)}
{rows.map((row, rowIndex) =>
<tr key={startIndex + rowIndex} title={rowError(row, rowIndex)} className={isSelected({ selection, index: rowNumber(rowIndex) }) ? 'selected' : undefined}>
<td style={cornerStyle} onClick={() => dispatch({ type: 'SET_SELECTION', selection: toggleIndex({ selection, index: rowNumber(rowIndex) }) })}>
<tr key={startIndex + rowIndex} title={rowError(row, rowIndex)} className={isSelected({ selection, index: rowNumber(rowIndex) }) ? 'selected' : ''}>
<td style={cornerStyle} onClick={() => selectable && dispatch({ type: 'SET_SELECTION', selection: toggleIndex({ selection, index: rowNumber(rowIndex) }) })}>
<span>{rowNumber(rowIndex).toLocaleString()}</span>
<input type='checkbox' checked={isSelected({ selection, index: rowNumber(rowIndex) })} />
</td>