Skip to main content

Save settings / Persistence

NatTable settings refer to the changes which the user makes to the grid while using it. The settings which are saved include but are not limited to the following:

  1. Hidden columns
  2. Column order
  3. Resized columns/rows
  4. Sorting state
  5. Column groups state
  6. Filter row state

The PersistentNatExample is a good place to get started.

Saving state

NatTable saves its state in a java.util.Properties file as key/value pairs. The main method to note is the

NatTable.saveState(prefix, properties)

To save state, invoke this method and give it a properties file. This file will be populated with all the sate information. You can now save this file anywhere/anyway you wish. Prefix is any arbitrary string which will be prepended to all the key values in the property file.

Loading state

The method to note is the

NatTable.loadState(String prefix, Properties properties)

The prefix and properties file are from the save state step.

Saving your custom state

The IPersistable interface is the main interface to note. All the layers which save state, implement this interface. Additionally, you can register your own persistable with any layer using the registerPersistable() on the ILayer interface. Your persistable will be invoked when NatTable state is saved/loaded.

NatTable persistable diagram

Back to the top