Search code examples
javaswtnattable

Nattable loose selection just after loading data


I'm using Nattable for almost all my tables in my application. Now an user reported an issue regarding the selection in Nattable.

When my application loads data the data is shown, when the user select an item just after the data loading, it will remove the selection. When the user wait a few seconds and does the selection again it holds.

Is this a known behavior of Nattable? For me it looks like the data is still loading when the first selection took place. The data load is 11K items with multiple cell labelers.


Solution

  • Without seeing the details it is hard to tell. Actually I wonder how something is rendered while the data is still loaded. But I suppose you have some interesting lazy loading mechanism to make the table accessible fast.

    From my experience the behavior you describe happens because of a StructuralChangeEvent. Once the data is completely loaded such an event is fired to update all layers accordingly. A structural change is used to completely clear, that also implies the selection when using the default SelectionModel. The selection in that model is stored by row index. But as a structural change means this could have been changed, the selection is removed to avoid that something is shown selected that was not selected before.

    Either you use an extended selection model like the RowSelectionModel or the PreserveSelectionModel or you double check when the StructuralChangeEvent is fired and if you can deal with that. But I suppose an alternative selection model should be more interesting with regards to your data loading mechanism.