- Qt 6.10
- QML Types
- QtQml.Models
- FunctionSorter
- Qt 6.10.3 Reference Documentation

# FunctionSorter QML Type

Sorts data in a SortFilterProxyModel based on the evaluation of the designated 'sort' method. More...

Import Statement: | `import QtQml.Models`
Since: | Qt 6.10
Inherits: | Sorter
Status: | Preliminary

This type is under development and is subject to change.

- List of all members, including inherited members

## Detailed Description

FunctionSorter allows user to define the designated 'sort' method and it will be evaluated to sort the data. The method takes two arguments (lhs and rhs) of the specified parameter type and the data can be accessed as below for evaluation,

     SortFilterProxyModel {
         model: sourceModel
         sorters: [
             FunctionSorter {
                 id: functionSorter
                 component RoleData: QtObject {
                     property real age
                 }
                 function sort(lhsData: RoleData, rhsData: RoleData) : int {
                     return (lhsData.age < rhsData.age) ? -1 : ((lhsData === rhsData.age) ? 0 : 1)
                 }
             }
         ]
     }

Note: The user needs to explicitly invoke SortFilterProxyModel::invalidateSorter whenever any external qml property used within the designated 'sort' method changes. This behaviour is subject to change in the future, like implicit invalidation and thus the user doesn't need to explicitly invoke SortFilterProxyModel::invalidateSorter.