allowSorting property

bool allowSorting
final

Decides whether user can sort the column simply by tapping the column header.

Defaults to false.

@override
Widget build(BuildContext context) {
  return SfDataGrid(
    source: _employeeDataSource,
    allowSorting: true,
    columns: [
        GridColumn(columnName: 'id', label: Text('ID')),
        GridColumn(columnName: 'name', label: Text('Name')),
        GridColumn(columnName: 'designation', label: Text('Designation')),
        GridColumn(columnName: 'salary', label: Text('Salary')),
  ]);
}

class EmployeeDataSource extends DataGridSource {
  @override
  List<DataGridRow> get rows => _employees
      .map<DataGridRow>((dataRow) => DataGridRow(cells: [
            DataGridCell<int>(columnName: 'id', value: dataRow.id),
            DataGridCell<String>(columnName: 'name', value: dataRow.name),
            DataGridCell<String>(
                columnName: 'designation', value: dataRow.designation),
            DataGridCell<int>(columnName: 'salary', value: dataRow.salary),
          ]))
      .toList();

  @override
  DataGridRowAdapter? buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((dataCell) {
      return Text(dataCell.value.toString());
    }).toList());
  }
}

See also:

Implementation

final bool allowSorting;