From 907bdf51b605d0c1f2187b068c3e73f993ef5419 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 24 Aug 2020 11:36:03 -0500 Subject: [PATCH] feat(data-table): add getCellId in filterRows (#6700) * feat(data-table): add getCellId in filterRows * feat(data-table): add getCellId to default filterRows Co-authored-by: Andrea N. Cardona --- packages/react/src/components/DataTable/DataTable.js | 3 +++ .../react/src/components/DataTable/tools/filter.js | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/react/src/components/DataTable/DataTable.js b/packages/react/src/components/DataTable/DataTable.js index 359194ec3987..17d1c59911f9 100644 --- a/packages/react/src/components/DataTable/DataTable.js +++ b/packages/react/src/components/DataTable/DataTable.js @@ -10,6 +10,7 @@ import React from 'react'; import isEqual from 'lodash.isequal'; import getDerivedStateFromProps from './state/getDerivedStateFromProps'; import { getNextSortState } from './state/sorting'; +import { getCellId } from './tools/cells'; import denormalize from './tools/denormalize'; import { composeEventHandlers } from '../../tools/events'; import { defaultFilterRows } from './tools/filter'; @@ -439,6 +440,7 @@ export default class DataTable extends React.Component { headers: this.props.headers, cellsById: this.state.cellsById, inputValue: this.state.filterInputValue, + getCellId, }) : this.state.rowIds; if (filteredRowIds.length == 0) { @@ -646,6 +648,7 @@ export default class DataTable extends React.Component { headers, cellsById, inputValue: filterInputValue, + getCellId, }) : rowIds; const renderProps = { diff --git a/packages/react/src/components/DataTable/tools/filter.js b/packages/react/src/components/DataTable/tools/filter.js index 32baaac93754..c258e9d8827b 100644 --- a/packages/react/src/components/DataTable/tools/filter.js +++ b/packages/react/src/components/DataTable/tools/filter.js @@ -5,8 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import { getCellId } from './cells'; - /** * Default implemention of how we filter rows internally. The idea behind this * implementation is to use the given list of row ids and headers to get the @@ -20,7 +18,13 @@ import { getCellId } from './cells'; * @param {string} config.inputValue the current input value in the Table Search * @returns {Array} rowIds */ -export const defaultFilterRows = ({ rowIds, headers, cellsById, inputValue }) => +export const defaultFilterRows = ({ + rowIds, + headers, + cellsById, + inputValue, + getCellId, +}) => rowIds.filter((rowId) => headers.some(({ key }) => { const id = getCellId(rowId, key);