diff --git a/docs/api.md b/docs/api.md index 0d969a8..349f565 100644 --- a/docs/api.md +++ b/docs/api.md @@ -103,13 +103,13 @@ The following options are supported via the main options object passed to `useTa - Defaults to `(row) => row.subRows || []` - Use this function to change how React Table detects subrows. You could even use this function to generate sub rows if you want. - By default, it will attempt to return the `subRows` property on the row, or an empty array if that is not found. -- `getRowPathID: Function(row, relativeIndex) => string` +- `getRowID: Function(row, relativeIndex) => string` + - Use this function to change how React Table detects unique rows and also how it constructs each row's underlying `path` property. - Optional - Must be **memoized** - Defaults to `(row, relativeIndex) => relativeIndex` - - Use this function to change how React Table constructs each row's underlying `path` property. - You may want to change this function if - - By default, it will attempt to return the `subRows` property on the row, or an empty array if that is not found. + - By default, it will use the `index` of the row within it's original array. - `debug: Bool` - Optional - A flag to turn on debug mode. diff --git a/src/hooks/useTable.js b/src/hooks/useTable.js index bfcf399..a623c93 100755 --- a/src/hooks/useTable.js +++ b/src/hooks/useTable.js @@ -20,7 +20,7 @@ const propTypes = { columns: PropTypes.arrayOf(PropTypes.object).isRequired, defaultColumn: PropTypes.object, getSubRows: PropTypes.func, - getRowPathID: PropTypes.func, + getRowID: PropTypes.func, debug: PropTypes.bool, } @@ -30,7 +30,7 @@ const renderErr = const defaultColumnInstance = {} const defaultGetSubRows = (row, index) => row.subRows || [] -const defaultGetRowPathID = (row, index) => index +const defaultGetRowID = (row, index) => index export const useTable = (props, ...plugins) => { // Validate props @@ -43,7 +43,7 @@ export const useTable = (props, ...plugins) => { columns: userColumns, defaultColumn = defaultColumnInstance, getSubRows = defaultGetSubRows, - getRowPathID = defaultGetRowPathID, + getRowID = defaultGetRowID, debug, } = props @@ -147,7 +147,7 @@ export const useTable = (props, ...plugins) => { // Keep the original reference around const original = originalRow - const rowID = getRowPathID(originalRow, i) + const rowID = getRowID(originalRow, i) // Make the new path for the row const path = [...parentPath, rowID] @@ -199,7 +199,7 @@ export const useTable = (props, ...plugins) => { if (process.env.NODE_ENV === 'development' && debug) console.timeEnd('getAccessedRows') return [accessedData, rowPaths, flatRows] - }, [debug, data, getRowPathID, getSubRows, flatColumns]) + }, [debug, data, getRowID, getSubRows, flatColumns]) instanceRef.current.rows = rows instanceRef.current.rowPaths = rowPaths