Thomas N. Thomas N. - 2 years ago 273
Java Question

JavaFX TableView - Resetting the column sorts

I am not looking to disable the sorting of a

when I click on the column header. But I am looking for a programmatic way to rid all column sorting at any time, as shown below in the screenshot in the ID column. I want that sort arrow gone.

The reason I need to remove the sorters at any time is because I have features that move searched records to the top, and sorting will mess this up. But I want to allow the user to sort whenever they want when they aren't using this feature.

I've spent probably 45 minutes digging through the
API looking for something that will turn it off. Is there a way to do this without binding to a
? I'd prefer not to mess with the items backing the
, but rather the

Answer Source

Got some help elsewhere from Jonathan Giles. You can remove the sorts by calling the following


Unfortunately, I didn't realize the sorters physically modified the backing ObservableList of items. So the solution would be to call the above method and re-order items manually that I've deemed to be the "natural order".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download