Skip to content

Commit 39f8840

Browse files
authored
adds passAdjacentKeyFields option (#682)
1 parent 64d6a07 commit 39f8840

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ When the breakpoint is reached the column will be hidden. These are the built-in
168168
| noTableHead | bool | no | false | hides the the sort columns and titles (TableHead) - this will obviously negate sorting |
169169
| persistTableHead | bool | no | | Show the table head (columns) even when `progressPending` is true. Note that the `noTableHead` will always hide the table head (columns) even when using `persistTableHead` |
170170
| direction | string | no | auto | Accepts: `ltr, rtl, or auto`. When set to `auto` (default), RDT will attempt to detect direction by checking the HTML and DIV tags. For cases where you need to force rtl, or ltr just set this option manually (i.e. SSR) |
171+
| passAdjacentKeyFields | bool | no | false | Adds `prevKeyField` and `nextKeyField` properties to the row object, containing the keyField value for the adjacent rows, if any |
171172

172173
#### Row Selection
173174

src/DataTable/DataTable.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const DataTable = memo(({
103103
theme,
104104
customStyles,
105105
direction,
106+
passAdjacentKeyFields,
106107
}) => {
107108
const initialState = {
108109
allSelected: false,
@@ -388,6 +389,12 @@ const DataTable = memo(({
388389
&& expandableRowDisabled
389390
&& expandableRowDisabled(row);
390391

392+
393+
if ( passAdjacentKeyFields ) {
394+
row.prevKeyField = typeof(calculatedRows[i-1]) != "undefined" ? calculatedRows[i-1][keyField] : false;
395+
row.nextKeyField = typeof(calculatedRows[i+1]) != "undefined" ? calculatedRows[i+1][keyField] : false;
396+
}
397+
391398
return (
392399
<TableRow
393400
id={id}

0 commit comments

Comments
 (0)