@carbon/react
Version:
React components for the Carbon Design System
30 lines (28 loc) • 1.02 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
//#region src/components/DataTable/tools/filter.ts
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Filters row IDs based on whether any of the cell values in the row include
* the input value as a substring. Boolean cell values are ignored.
*/
const defaultFilterRows = ({ rowIds, headers, cellsById, inputValue, getCellId }) => {
const normalizedInput = inputValue.trim().toLowerCase();
if (!normalizedInput) return rowIds;
return rowIds.filter((rowId) => headers.some(({ key }) => {
const cell = cellsById[getCellId(rowId, key)];
if (typeof cell.value === "boolean") return false;
return String(cell.value).toLowerCase().includes(normalizedInput);
}));
};
//#endregion
export { defaultFilterRows };