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

I’m working with Vaadin 7.5 RC2 and as a result I’m working with the ability to have columns hidden, the columns can be re-ordered, and so on.

With that in mind is it possible to extract these values from a grid so that I can save the way the user setup their grid for the next time they come to the website? For example perhaps they changed the default column ordering, changed which columns are hidden and visible by default, maybe even the sorting order of the columns, and what I want to do is save all this so that the next time they come the grid is in exactly the same state. The data may not be the same but the view of the grid is the same.

I can’t see how to do this, which I suspect is because it’s not possible, but if it is, then I would really appreciate knowing how. Thank you.

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.

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.

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.

Another quick question, is it possible in Vaadin 7.5 to let the user change the column widths? If so then how do you do this? Otherwise there’s no point in saving the column widths as preferences.

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

That’s good news! Any idea what the roadmap is, as in for what version? Or is it still to be determined?