performSorting method

  1. @protected
Future<void> performSorting(
  1. List<DataGridRow> rows
)
inherited

Called when the sorting is applied to the column.

Overriding this method gives complete control over sorting. You can handle the sorting completely in your own way. The rows argument provides the unsorted DataGridRow collection.

You can apply the sorting to rows argument. DataGrid will render the rows based on the rows argument. You don’t need to call notifyListeners within this method. However, you must override this method only if you want to write the entire sorting logic by yourself. Otherwise, for custom comparison, you can just override DataGridSource.compare method and return the custom sorting order.

For most of your cases, the 'compare' method should be sufficient. The DataGridSource.compare method can be used to do custom sorting based on the length of the text, case insensitive sorting, and so on.

See also,

DataGridSource.compare – To write the custom sorting for most of the use cases.

Implementation

@protected
Future<void> performSorting(List<DataGridRow> rows) async {
  if (sortedColumns.isEmpty) {
    return;
  }
  rows.sort((DataGridRow a, DataGridRow b) {
    return _compareValues(sortedColumns, a, b);
  });
}