Sort by Clicking on Column Headers in QML TableView
-
I am trying to create a table in QML, connected to a model, which allows sorting asc/desc by clicking on the column header. I have created a TableView in QML, connected to QSortFilterProxyModel, connected to QAbstractTableModel, and so far so good. But I'm stuck on how to add sorting by clicking on column headers in QML.
In the documentation for QSortFilterProxyModel, it says that in order to sort the contents of the accompanying view, you have to set the sortingEnabled property in the accompanying QTableView (could be a QListView, QTableView, or QTreeView) to true using setSortingEnabled(bool enable). Enabling this property seems to magically add click to sort capabilities to the columns...in C++'s QTableView.
However, I'm working in QML. How can I achieve the same for my QML TableView? I thought about subclassing the QTableView and exposing it to QML but that seems like a lot of work for something which is probably already available somehow.