performSorting method Null safety

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

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
void performSorting(List<DataGridRow> rows) {
  if (sortedColumns.isEmpty) {
    return;
  }
  rows.sort((DataGridRow a, DataGridRow b) {
    return _compareValues(sortedColumns, a, b);
  });
}