Skip to content

Commit

Permalink
feat(data-table): add getCellId in filterRows (#6700)
Browse files Browse the repository at this point in the history
* feat(data-table): add getCellId in filterRows

* feat(data-table): add getCellId to default filterRows

Co-authored-by: Andrea N. Cardona <[email protected]>
  • Loading branch information
joshblack and andreancardona authored Aug 24, 2020
1 parent 019b5e7 commit 907bdf5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/react/src/components/DataTable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -646,6 +648,7 @@ export default class DataTable extends React.Component {
headers,
cellsById,
inputValue: filterInputValue,
getCellId,
})
: rowIds;
const renderProps = {
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/components/DataTable/tools/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +18,13 @@ import { getCellId } from './cells';
* @param {string} config.inputValue the current input value in the Table Search
* @returns {Array<string>} 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);
Expand Down

0 comments on commit 907bdf5

Please sign in to comment.