Interface ColumnPreferenceStorage
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
BrowserColumnPreferenceStorage, InMemoryColumnPreferenceStorage, JdbcColumnPreferenceStorage, ServerSideColumnPreferenceStorage
Stores a user's column visibility preference for an
AdvancedGrid.
A preference is a map of column id to visibility (see ColumnPreferences#columnId),
kept under a key that identifies one grid (see ColumnPreferenceContext.key()).
Ready-made implementations:
localStorage(): the browser'slocalStorage; kept until the user clears browser data, per browser and device (the default).sessionStorage(): the browser'ssessionStorage; kept until the tab closes.JdbcColumnPreferenceStorage: a database table, per signed-in user, following the user across browsers and devices.InMemoryColumnPreferenceStorage: server memory, per user; for prototypes and tests.
To store elsewhere (a REST service, Redis, a JPA repository), extend ServerSideColumnPreferenceStorage for any synchronous server-side destination, or implement
this interface directly for asynchronous ones.
Implementations must not throw from these methods for storage failures: a preference is a convenience, and the grid must keep working with its default columns when storage is unavailable. Log the failure and report an empty preference instead.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear(ColumnPreferenceContext context) Removes the preference stored under the context's key, if any.voidload(ColumnPreferenceContext context, com.vaadin.flow.function.SerializableConsumer<Map<String, Boolean>> onLoaded) Loads the preference and passes it toonLoaded, possibly later (for example after a browser round trip).static ColumnPreferenceStorageStores preferences in the browser'slocalStorage.voidsave(ColumnPreferenceContext context, Map<String, Boolean> visibility) Stores the preference, replacing any previous one under the same key.static ColumnPreferenceStorageStores preferences in the browser'ssessionStorage(cleared when the tab closes).
-
Method Details
-
load
void load(ColumnPreferenceContext context, com.vaadin.flow.function.SerializableConsumer<Map<String, Boolean>> onLoaded) Loads the preference and passes it toonLoaded, possibly later (for example after a browser round trip). Pass an empty map when nothing is stored. Must be called on the UI thread (with the session locked), as the grid applies the result directly. -
save
Stores the preference, replacing any previous one under the same key. -
clear
Removes the preference stored under the context's key, if any. -
localStorage
Stores preferences in the browser'slocalStorage. -
sessionStorage
Stores preferences in the browser'ssessionStorage(cleared when the tab closes).
-