Skip to content

[8.19] [Lens][Table] Fix csv export column sort order (#236673)#237018

Merged
nickofthyme merged 1 commit intoelastic:8.19from
nickofthyme:backport/8.19/pr-236673
Oct 1, 2025
Merged

[8.19] [Lens][Table] Fix csv export column sort order (#236673)#237018
nickofthyme merged 1 commit intoelastic:8.19from
nickofthyme:backport/8.19/pr-236673

Conversation

@nickofthyme
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.19:

Questions ?

Please refer to the Backport tool documentation

## Summary

When a table from a dashboard using the **Download CSV** action, the
column sort order visible in the table on the dashboard are preserved in
the csv output.

https://github.com/user-attachments/assets/7454a511-150b-45a2-86c5-1cd61bc0191a

Fixes elastic#236550

## Details

The `datatable_fn` is used to set the table of data to the `adapters`,
which is the data used in the csv export action. This data comes in out
of order with additional `Part of X` columns for formula columns.
However, we do not sort these in before passing to the adapters.
Normally, with formulas, this is not a problem as the columns are in the
correct order but the
[`tabify`](https://github.com/elastic/kibana/blob/8d4b0956586284c35db97de2baea49b58476ee2a/src/platform/plugins/shared/data/common/search/tabify/tabify.ts#L24)
logic mixes up the column order for formulas.

The fix is to simply sort the columns in the table before passing it to
the `adapters.`

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

## Release Note

Fixes a bug in the Lens table in which exporting the table from a
dashboard, which containg formula columns, can result in a different
column order than shown on the dashboard.

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
(cherry picked from commit ef105c5)

# Conflicts:
#	x-pack/platform/plugins/shared/lens/common/expressions/datatable/datatable_fn.test.ts
@nickofthyme nickofthyme added the backport This PR is a backport of another PR label Sep 30, 2025
@nickofthyme nickofthyme enabled auto-merge (squash) September 30, 2025 17:32
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.5MB 1.5MB +376.0B

@nickofthyme nickofthyme merged commit ff0d788 into elastic:8.19 Oct 1, 2025
11 checks passed
@nickofthyme nickofthyme deleted the backport/8.19/pr-236673 branch October 1, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants