-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
The main issue is that when we use dynamic fields in DatagridConfigurable together with SelectColumnsButton, the result works very strangely.
I will try to demonstrate the situation visually and also prepare a sandbox environment for reproduction.
Let’s imagine that we have a complex Datagrid with tabs. For example, we’ll have two tabs: one for sms data and another for email data.
Each entity (SMS and Email) can have its own fields, for example:
sms: date, full price, total, cost
email: date, total, size
When we switch between the tabs, there are no issues.
Now, let’s focus on the SelectColumnsButton. The dropdown list of fields in the SelectColumnsButton does not respond to tab switching, even though the fields in the Datagrid change.
The SelectColumnsButton simply uses the fields from the default tab, ignoring any tab switches.
Furthermore, if we try to disable totalPrice (which doesn’t exist for Email), the total field disappears from the Datagrid. This is likely due to index misalignment—SelectColumnsButton seems to rely on the sequence of fields and disables the first one in the list.
I also tried performing a refresh, but that doesn’t work either.
What you were expecting:
I think the fields in the SelectColumnsButton should update together with the DatagridConfigurable. Additionally, it’s probably better to use source instead of relying on the index.
Steps to reproduce:
You can use the sandbox from the Related code section, go to the tests section (the last icon), ensure the SMS tab is open, and check the fields in COLUMNS. Then switch to the Email tab to confirm that the table changes, but COLUMNS remains the same.
Related code:
I was able to reproduce this behavior in the last test tab:
https://bolt.new/~/github-apt5o9-wbtm9a
Other information:
Currently, I managed to work around the issue by creating custom components, CustomSelectColumnsButton and CustomDatagridConfigurable, and overriding the preferenceKey:
preferences.${finalPreferenceKey}.availableColumns
to
preferences.${finalPreferenceKey}.availableColumns_${mode}
while adding the corresponding logic.
I don’t think this is an ideal solution, but I couldn’t find a better way.
Environment
- React-admin version: 5.3.3
- Last version that did not exhibit the issue (if applicable): ---
- React version: 18.3.1
- Browser: doesn't matter
- Stack trace (in case of a JS error): doesn't matter