Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Is it possible to save the user settings of a grid (column ordering, etc.)

Stephan Grenier
7 years ago Jun 24, 2015 3:03am
Tatu Lund
7 years ago Jun 24, 2015 8:25am

I think this should be atleast partially doable. For example Grid has getColumns method, which returns the columns in the displayed order. So it is possible to iterate the column list in correct order and collect the column specific settings, with getWidth, getHeaderCaption etc. methods. You can store this data into database and when you setup the Grid next time, you can use the same data.

Kim Leppänen
7 years ago Jun 24, 2015 9:38am

Tatu is on the right track. Regarding APIs, grid has a getSortOrder() which gives you a list of SortOrder objects, which in its turn contains information about the property id and its sort order.

Regarding column order and what is hidden and what is show; as mentioned, getColumns returns a list of Column objects, which indicate in which order the columns are in the grid. The Column class has a method getPropertyId() which you can use for getting the property id and storing the order for persistance. The Column class also has an isHidden() method, which will tell you if the column is visible or not.

Stephan Grenier
7 years ago Jun 24, 2015 5:52pm

Thank you, this does help a lot. I wasn't sure if the collection of columns was in the correct order, especially if they changed the ordering of the columns. 

As you guys said, I believe I may have everything I need, that was the last piece of the puzzle I was missing. Without that guarantee it would've been challenging. I tried to look through the source and couldn't see any guarantees. Thanks for confirming it.

That being said it would be cool if there was a way to store an encoded String, something like grid.getTableSettings() or whatever. I understand there are complications in that the table may not be the same and you would have to adjust for it, but it would be cool for the future. Anyways something to think about for the future.

Stephan Grenier
7 years ago Jun 24, 2015 8:18pm
Tatu Lund
7 years ago Jun 25, 2015 5:16am

That feature is in the queue for future versions, not yet implemented in 7.5 though. The ticket is here.


Stephan Grenier
7 years ago Jun 25, 2015 4:56pm