src/selectors.js
function filter(rows = [], filters = [], filterText, columns) {
  let filteredRows = rows.slice(0);
  if (filters.length === 0 && !filterText) {
    return filteredRows;
  }

  const textFilters = [
    ...(filterText ? [filterText.toLowerCase()] : []),
    ...filters.filter(f => f.textFilter).map(f => f.value),
  ];

  const valueFilters = filters.filter(f => f.valueFilter);

  // apply text filters across all columns
  if (textFilters.length > 0) {
    filteredRows = _.filter(rows, row => _.some(columns, (column) => {
      if (!column.searchable) {
        return false;
      }
      const normalized = String(_.get(row, column.key)).toLowerCase();
      return _.every(textFilters, f => normalized.indexOf(f) > -1);
    }));
  }

  // apply value filters on filterable columns
  if (valueFilters.length > 0) {
    const groups = _.groupBy(valueFilters, 'key');
    filteredRows = _.filter(filteredRows, row => _.every(
      groups,
      (groupFilters, groupKey) => {
        const value = _.get(row, groupKey);
        return _.some(groupFilters, f => f.value === value);
      }
    ));
  }

  return filteredRows;
}
function filter(rows = [], filters = [], filterText, columns) {
  let filteredRows = rows.slice(0);
  if (filters.length === 0 && !filterText) {
    return filteredRows;
  }

  const textFilters = [
    ...(filterText ? [filterText.toLowerCase()] : []),
    ...filters.filter(f => f.textFilter).map(f => f.value),
  ];

  const valueFilters = filters.filter(f => f.valueFilter);

  // apply text filters across all columns
  if (textFilters.length > 0) {
    filteredRows = _.filter(rows, row => _.some(columns, (column) => {
      if (!column.searchable) {
        return false;
      }
      const normalized = String(_.get(row, column.key)).toLowerCase();
      return _.every(textFilters, f => normalized.indexOf(f) > -1);
    }));
  }

  // apply value filters on filterable columns
  if (valueFilters.length > 0) {
    const groups = _.groupBy(valueFilters, 'key');
    filteredRows = _.filter(filteredRows, row => _.every(
      groups,
      (groupFilters, groupKey) => {
        const value = _.get(row, groupKey);
        return _.some(groupFilters, f => f.value === value);
      }
    ));
  }

  return filteredRows;
}
function filter ( rows = [ ] , filters = [ ] , filterText , columns ) { let filteredRows = rows . slice ( 0 ) ; if ( filters . length === 0 && ! filterText ) { return filteredRows ; } const textFilters = [ ... ( filterText ? [ filterText . toLowerCase ( ) ] : [ ] ) , ... filters . filter ( f => f . textFilter ) . map ( f => f . value ) , ] ; const valueFilters = filters . filter ( f => f . valueFilter ) ; // apply text filters across all columns if ( textFilters . length > 0 ) { filteredRows = _ . filter ( rows , row => _ . some ( columns , ( column ) => { if ( ! column . searchable ) { return false ; } const normalized = String ( _ . get ( row , column . key ) ) . toLowerCase ( ) ; return _ . every ( textFilters , f => normalized . indexOf ( f ) > - 1 ) ; } ) ) ; } // apply value filters on filterable columns if ( valueFilters . length > 0 ) { const groups = _ . groupBy ( valueFilters , 'key' ) ; filteredRows = _ . filter ( filteredRows , row => _ . every ( groups , ( groupFilters , groupKey ) => { const value = _ . get ( row , groupKey ) ; return _ . some ( groupFilters , f => f . value === value ) ; } ) ) ; } return filteredRows ; }
rows - original data
filters - list of selected filters
filterText - currently entered text in filter input
columns - column definitions
rows - original data filters - list of selected filters filterText - currently entered text in filter input columns - column definitions