iTwin / iTwinUI-react

A react component library for iTwinUI.
https://github.com/iTwin/iTwinUI
Other
83 stars 23 forks source link

Table: Column order is not respected when external columns change #900

Closed HaveSpacesuit closed 1 year ago

HaveSpacesuit commented 1 year ago

When changing columns after dragging a column, the new columns are in an unexpected order.

To reproduce:

https://codesandbox.io/s/itwinui-react-minimal-example-forked-3cxy87?file=/src/App.tsx Column order changes

HaveSpacesuit commented 1 year ago

This is a minor issue. We've implemented a work around in our app with a state reducer which compares the order of the columns we expect versus the order of the columns in the ReactTable state. But if there was an easy fix, it would help.

mayank99 commented 1 year ago

@HaveSpacesuit Thanks for the update. We plan to look into this after our major release, which should happen very soon.

r100-stack commented 1 year ago

This is happening because of the stale columnOrder affecting the new columns.

In your example:

  1. Initially, columns = [index, name, desc], columnOrder = []
  2. Drag desc to name. columns = [index, name, desc], columnOrder = [index, desc, name]
  3. Now we pass new columns to Table. columns = [id, name, startDate, endDate], columnOrder = [index, desc, name]

Since name from columns is in columnOrder, that is the first column displayed. Since the other three columns are not in columnOrder, it is displayed in the same order as passed in columns.

That is why the final order in your screenshot is [name] (fixed) + [id, startDate, endDate] (remaining)

Docs:

image

One fix could be to reset the columnOrder to [] when columns changes. I made a PR #983 with this fix. If there is a better approach, I will update this PR to that approach.