allowSorting property Null safety

bool allowSorting

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

Defaults to false.

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 {
  List<DataGridRow> get rows => _employees
      .map<DataGridRow>((dataRow) => DataGridRow(cells: [
            DataGridCell<int>(columnName: 'id', value:,
            DataGridCell<String>(columnName: 'name', value:,
                columnName: 'designation', value: dataRow.designation),
            DataGridCell<int>(columnName: 'salary', value: dataRow.salary),

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

See also:


final bool allowSorting;