Skip to content

[Lens][Table] Fix filtering on tables with formula columns#239222

Merged
nickofthyme merged 1 commit intoelastic:mainfrom
nickofthyme:fix-table-formula-filter
Oct 15, 2025
Merged

[Lens][Table] Fix filtering on tables with formula columns#239222
nickofthyme merged 1 commit intoelastic:mainfrom
nickofthyme:fix-table-formula-filter

Conversation

@nickofthyme
Copy link
Contributor

@nickofthyme nickofthyme commented Oct 15, 2025

Summary

Fixes a bug in the Lens Table that broke click to filter on table rows when any column is used as a formula.

Zight.Recording.2025-10-15.at.01.31.51.PM.mp4

Fixes #239170

Details

In #236673 We added column sorting to export the correct order to csv. The issue is that the formula columns create ghost columns in the datatable used to build-up the real columns. These use the id <colId>X<number> and are removed from the export so as long as the order of the real columns was correct it was fine.

However, with filtering we use the colIndex to define the column to filter.

export const createGridFilterHandler =
(
tableRef: React.MutableRefObject<Datatable>,
onClickValue: (data: ClickTriggerEvent['data']) => void
) =>
(_field: string, value: unknown, colIndex: number, rowIndex: number, negate: boolean = false) => {
const data: ClickTriggerEvent['data'] = {
negate,
data: [
{
row: rowIndex,
column: colIndex,
value,
table: tableRef.current,
},
],
};
onClickValue(data);
};

With the non-bucketed (aka Metrics) columns, we a lookup table to map the column id to the meta data including the column index of the full table, including the ghost columns. This is why this filtering was not also broken.

Untitled

const columnsReverseLookup = buildColumnsMetaLookup(table);

But with the bucketed columns (aka Rows), we determine the column index from the columnConfig with excludes the ghost columns. Hence the issue, we were sorting the ghost columns to the front of the array such that all the indices of the real columns would be offset by the number of ghost columns.

All that said, a simple fix would be to just sort the real columns to the start of the array and leave unknown/ghost columns to the end as their order does not matter. Alternatively, we could create a lookup similar to above to lookup the index on the full table but I don't think that is necessary if we enforce the correct order.

Ideally, we filter by passing the columnId and not the colIndex. In this way there is no ambiguity and the createGridFilterHandler has the table to lookup the correct index from the table.columns. See #239224.

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

Minimal as sorting is the only impact.

Release Notes

Fixes a bug in the Lens Table that broke click to filter on table rows when any column is used as a formula.

Copy link
Contributor

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM for a quick fix

@nickofthyme nickofthyme added release_note:fix backport:all-open Backport to all branches that could still receive a release Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// Feature:Lens labels Oct 15, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@nickofthyme nickofthyme merged commit b0bac3d into elastic:main Oct 15, 2025
22 checks passed
@nickofthyme nickofthyme deleted the fix-table-formula-filter branch October 15, 2025 20:57
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.18, 8.19, 9.1, 9.2

https://github.com/elastic/kibana/actions/runs/18542454977

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 15, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.

(cherry picked from commit b0bac3d)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 15, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.

(cherry picked from commit b0bac3d)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 15, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.

(cherry picked from commit b0bac3d)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 15, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.

(cherry picked from commit b0bac3d)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.18
8.19
9.1
9.2

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@nickofthyme nickofthyme added v9.1.6 and removed v9.1.6 labels Oct 15, 2025
kibanamachine added a commit that referenced this pull request Oct 15, 2025
…9222) (#239234)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[Lens][Table] Fix filtering on tables with formula columns
(#239222)](#239222)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"nicholas.partridge@elastic.co"},"sourceCommit":{"committedDate":"2025-10-15T20:57:22Z","message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:all-open","v9.3.0"],"title":"[Lens][Table]
Fix filtering on tables with formula
columns","number":239222,"url":"https://github.com/elastic/kibana/pull/239222","mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239222","number":239222,"mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <nicholas.partridge@elastic.co>
kibanamachine added a commit that referenced this pull request Oct 15, 2025
…9222) (#239235)

# Backport

This will backport the following commits from `main` to `9.2`:
- [[Lens][Table] Fix filtering on tables with formula columns
(#239222)](#239222)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"nicholas.partridge@elastic.co"},"sourceCommit":{"committedDate":"2025-10-15T20:57:22Z","message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:all-open","v9.3.0"],"title":"[Lens][Table]
Fix filtering on tables with formula
columns","number":239222,"url":"https://github.com/elastic/kibana/pull/239222","mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239222","number":239222,"mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <nicholas.partridge@elastic.co>
kibanamachine added a commit that referenced this pull request Oct 15, 2025
…39222) (#239233)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Lens][Table] Fix filtering on tables with formula columns
(#239222)](#239222)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"nicholas.partridge@elastic.co"},"sourceCommit":{"committedDate":"2025-10-15T20:57:22Z","message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:all-open","v9.3.0"],"title":"[Lens][Table]
Fix filtering on tables with formula
columns","number":239222,"url":"https://github.com/elastic/kibana/pull/239222","mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239222","number":239222,"mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <nicholas.partridge@elastic.co>
kibanamachine added a commit that referenced this pull request Oct 15, 2025
…39222) (#239232)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Lens][Table] Fix filtering on tables with formula columns
(#239222)](#239222)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"nicholas.partridge@elastic.co"},"sourceCommit":{"committedDate":"2025-10-15T20:57:22Z","message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:all-open","v9.3.0"],"title":"[Lens][Table]
Fix filtering on tables with formula
columns","number":239222,"url":"https://github.com/elastic/kibana/pull/239222","mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239222","number":239222,"mergeCommit":{"message":"[Lens][Table]
Fix filtering on tables with formula columns (#239222)\n\n##
Summary\n\nFixes a bug in the Lens Table that broke **click to filter**
on table rows when any column is used as a formula.\n\n## Release
Notes\n\nFixes a bug in the Lens Table that broke **click to filter** on
table\nrows when any column is used as a
formula.","sha":"b0bac3df208a70bda7509fb96709d24d78dd2aba"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <nicholas.partridge@elastic.co>
mgadewoll pushed a commit to tkajtoch/kibana that referenced this pull request Oct 17, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.
nickpeihl pushed a commit to nickpeihl/kibana that referenced this pull request Oct 23, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Oct 27, 2025
…39222)

## Summary

Fixes a bug in the Lens Table that broke **click to filter** on table rows when any column is used as a formula.

## Release Notes

Fixes a bug in the Lens Table that broke **click to filter** on table
rows when any column is used as a formula.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:all-open Backport to all branches that could still receive a release Feature:Lens release_note:fix Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v8.18.9 v8.19.6 v9.1.6 v9.2.0 v9.3.0

4 participants