Skip to content

fix(DataTable): don't match empty or object cell values when filtering - #23993

Open
officialasishkumar wants to merge 4 commits into
carbon-design-system:mainfrom
officialasishkumar:fix/23990-datatable-filter-empty-cells
Open

officialasishkumar wants to merge 4 commits into
carbon-design-system:mainfrom
officialasishkumar:fix/23990-datatable-filter-empty-cells

Conversation

@officialasishkumar

Copy link
Copy Markdown

Closes #23990

The default filterRows implementation in DataTable compared the search text against String(cell.value) for everything except booleans. Empty null/undefined cells therefore matched searches such as "nu" or "def". Cells holding a plain object or a React element (for example a <Link>) matched "object" through [object Object]. Either way, the table kept rows with no visible match for what the user typed.

defaultFilterRows now skips null, undefined, booleans, and objects that only have the default Object.prototype.toString. Strings, numbers (including 0), and objects with their own string form, such as arrays and Dates, are matched as before.

It also reads the cell value with optional chaining. Previously, a missing cell threw a TypeError whenever no earlier cell in the row matched; the existing "should handle a missing cell gracefully" test only passed because its search term matched the first cell.

Changelog

New

  • Tests for empty, object, and React element cell values, objects with a custom string form, zero, and a missing cell when nothing matches

Changed

  • defaultFilterRows ignores cell values without filterable text instead of matching their String() output

Removed

  • N/A

Testing / Reviewing

  1. Render a filterable DataTable with rows such as { id: 'a', name: 'Alpha', owner: null } and { id: 'b', name: 'Beta', owner: 'Kim' }.
  2. Type nu into the search. Row a is no longer shown; before this change it matched through "null".
  3. Give a column a React element value (for example <a href="#">Docs</a>) and search object: no rows match.
  4. Search for visible text such as kim or a number: matching works as before.

yarn test packages/react/src/components/DataTable passes (31 suites, 275 tests). Four of the new filter tests fail without the change to filter.ts.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples (the existing filterRows docs still describe the behavior accurately)
  • Followed the
    required v12 migration documentation
    for any code change that affects v12, or struck through this item because
    the PR does not affect v12
    (shared logic, not behind any v12 flag)
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency (logic-only change with no browser-specific behavior; verified in jsdom and headless Chromium)
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the DCO.
Posted by the DCO Assistant Lite bot.

@netlify

netlify Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v12-carbon-web-components ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b04de82
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-web-components/deploys/6afb1dfe6d253864a35eca90
😎 Deploy Preview https://deploy-preview-23993--v12-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

👷 Deploy request for v12-carbon-react pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit b04de82

@netlify

netlify Bot commented Nov 7, 2026

Copy link
Copy Markdown

✅ Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 3787902
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6aeee8633c4fa1ecd4e74e74
😎 Deploy Preview https://deploy-preview-23993--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b04de82
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6afb1dfe30a74d5b9b22135a
😎 Deploy Preview https://deploy-preview-23993--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit b04de82
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6afb1dfebfe0b6f17cc5dd32
😎 Deploy Preview https://deploy-preview-23993--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@carbon-monitor-agent

Copy link
Copy Markdown
Collaborator

[AI agent review — Carbon grounded] · Looks Good · Reviewed by: IBM Bob · Commit: 3787902

This PR updates defaultFilterRows in DataTable to ignore empty, boolean, plain object, and React element cell values during filtering, and guards against missing cells. 0 findings.

@officialasishkumar

Copy link
Copy Markdown
Author

I have read the DCO document and I hereby sign the DCO.

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.54%. Comparing base (fa75d78) to head (1c0b098).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23993      +/-   ##
==========================================
- Coverage   91.24%   90.54%   -0.70%     
==========================================
  Files         905      814      -91     
  Lines       81020    78931    -2089     
  Branches    10697    10304     -393     
==========================================
- Hits        73926    71469    -2457     
- Misses       6902     7259     +357     
- Partials      192      203      +11     
Flag Coverage Δ
main-packages 88.09% <ø> (-0.14%) ⬇️
web-components 91.28% <ø> (-0.70%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}

return (
typeof value !== 'object' || value.toString !== Object.prototype.toString

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects without an inherited toString method pass this check but then cause String(value) to throw an error. Is there a reason you chose this approach over another?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong reason, that was an oversight. It now also checks that toString is a function, so Object.create(null) is skipped, and I added a test for it.

`defaultFilterRows` matched the search text against `String(cell.value)`
for every value except booleans. Rows with an empty `null` or
`undefined` cell matched searches such as "nu" or "def", and cells whose
value is a plain object or a React element matched "object" through
`[object Object]`, so the table kept rows with no visible match.

Skip `null`, `undefined`, booleans, and objects that rely on the
default `Object.prototype.toString`. Strings, numbers (including 0),
and objects with their own string form, such as arrays and dates, are
matched as before.

Also read the cell value with optional chaining, so a missing cell no
longer throws a TypeError when no earlier cell in the row matched.

Closes carbon-design-system#23990

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
typeof value.toString === 'function' &&
value.toString !== Object.prototype.toString
);
};

@adamalston adamalston Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the value be converted to a string once instead? Cross realm plain objects can still pass this check, and accessing toString here and again during String(value) can invoke a getter twice. String conversion can also throw an error.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Execution_model#realms

Edit: Hmm, even if the value is converted to a string once, the conversion can still invoke inherited methods. Could the default filter limit string conversion to explicitly supported types instead of using prototype checks?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It now converts only strings, numbers and bigints to text and ignores everything else, so no toString is ever invoked (officialasishkumar@b04de82).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright IBM Corp. 2025, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the copyright year (officialasishkumar@b04de82).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright IBM Corp. 2016, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the copyright year (officialasishkumar@b04de82).

Convert only strings, numbers and bigints to text so the filter never calls toString on arbitrary objects, and update copyright years.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

This branch was successfully deployed

1 active (outdated) deployment
@carbon/react storybook preview — 1c0b098c Deployed Nov 16, 2026 by officialasishkumar via react-storybook-preview #45232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DataTable search matches empty cells and React element values as "null", "undefined", or "[object Object]"

3 participants