Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datatable column order state is not saved #2346

Closed
juanparati opened this issue Mar 23, 2022 · 2 comments
Closed

Datatable column order state is not saved #2346

juanparati opened this issue Mar 23, 2022 · 2 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working vue2
Milestone

Comments

@juanparati
Copy link

[X] bug report => Search github for a similar issue or PR before submitting
[X] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primevue/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=110

I observed that datatable code has missing the part save the column order state.

For example the method "onColumnHeaderDrop" doesn't call the "saveState" method, exactly like it happens with the methods "onColumnResizeEnd" or "updated".

The cause may also that state is not saved because datatable 2.9.1 calls to "beforeUnmount" instead of "beforeDestroy" method. The "beforeUnmount" is not available in Vue 2.x.

Expected behavior
The order of the columns should be saved and restored when the cache the state is used in a datatable exactly like it happens with the filters, sorting and data.

Minimal reproduction of the problem with instructions

  1. Set a datatable with "state-key" and "state-storage" and "reorderable-columns".
  2. Drag and drop one of the table column to another position.
  3. Reload databable page.
  • Vue version: 2.6.11

  • PrimeVue version: 2.9.1

  • Browser: all

@juanparati
Copy link
Author

I found the solution to this problem:

It seems that state is saved correctly, the problem is when the state is restored.

I replaced:

 if (this.reorderableColumns) {
                this.d_columnOrder = restoredState.columnOrder;
 }

by

 if (this.reorderableColumns) {
                this.$nextTick(() => this.d_columnOrder = restoredState.columnOrder);
 }

and now it works!.

I also recomend to rename "beforeUnmount" method to "beforeDestroy" on Vue 2.x component and save the state on "beforeDestroy" instead of "update". The component peformance improve a bit with this change.

@tugcekucukoglu tugcekucukoglu added vue2 Status: Pending Review Issue or pull request is being reviewed by Core Team labels Mar 28, 2022
@mertsincan mertsincan self-assigned this Aug 22, 2022
@mertsincan mertsincan added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Aug 22, 2022
@mertsincan mertsincan added this to the 2.10.0 milestone Aug 22, 2022
@mertsincan
Copy link
Member

Fixed in 6c97e0a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working vue2
Projects
None yet
Development

No branches or pull requests

3 participants