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

Table | custom state save/restore [new feature] #14461

Closed
cervenf opened this issue Jan 2, 2024 · 6 comments
Closed

Table | custom state save/restore [new feature] #14461

cervenf opened this issue Jan 2, 2024 · 6 comments
Labels
Type: New Feature Issue contains a new feature or new component request

Comments

@cervenf
Copy link

cervenf commented Jan 2, 2024

Describe the bug

At the moment table support only to store state (pagination, sorting, filtering options) to session or local storage.
Would be nice to have possibility to implement custom state save and restore.

Environment

not important

Reproducer

No response

Angular version

17

PrimeNG version

17

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@cervenf cervenf added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 2, 2024
@mehmetcetin01140 mehmetcetin01140 added Type: New Feature Issue contains a new feature or new component request and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jan 5, 2024
@critchie
Copy link

critchie commented Jan 7, 2024

@cervenf I needed something like you're asking for so I came up with this table-manager service. Take a look at this StackBlitz and see if it will help you.

Table Manager

@cervenf
Copy link
Author

cervenf commented Feb 6, 2024

@critchie Sorry for late replay. Thank you very much for the answer and also code sharing.

If I understand Table manager correctly it helps mainly in these 2 things:
[columns]="tableManager.selectedColumns"
[globalFilterFields]="tableManager.filterFields"
And rest is stored to local storage via: stateStorage="local"

Is there some way to store/restore sorting and filtering, please?

In my case, I have tree as navigation and I'm displaying data in table based on which node is selected.
Grid is reused and in some cases I would like to keep filters and sort. But not pageNumber and page size because data are different.
Thank you.

@critchie
Copy link

critchie commented Feb 6, 2024

@cervenf When you create a new instance of TableManager the constructor will read in the data from local storage. Line 45 in the ngOnInit() is where new TableManager is called. If you take a look at the TableManager constructor you will see where it does the read from local storage. All the rest is standard Angular binding. The ngAfterViewInit() is needed to assign the actual table to the TableManager. I had to do it this way because the table isn’t fully built and available until AfterViewInit.

@cervenf
Copy link
Author

cervenf commented Feb 7, 2024

I mean, I would like to store only sorting (column names, order etc.) and filtering (column names, operator..) and not current page.
I would like to not use :
<p-table
stateStorage="local"

But then I don't know how to restore (initialise table) with stored values.

@cervenf
Copy link
Author

cervenf commented Mar 11, 2024

Thank you.

I didn't know that p-table has these properties which I can set manually:
<p-table
[filters]=...
[multiSortMeta]=...
[rows]=

I'm using lazyload tables and I can store those values during (onLazyLoad) and restore them in the constructor.

@mehmetcetin01140
Copy link
Contributor

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Issue contains a new feature or new component request
Projects
None yet
Development

No branches or pull requests

3 participants