sort method

Future<void> sort()
inherited

Call this method when you are adding the SortColumnDetails programmatically to the DataGridSource.sortedColumns.

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('Syncfusion Flutter DataGrid'),
    ),
    body: Column(
      children: [
        FlatButton(
          child: Text('Click'),
          onPressed: () {
            _employeeDataSource.sortedColumns
                .add(SortColumnDetails('id', SortDirection.ascending));
            _employeeDataSource.sort();
          },
        ),
        SfDataGrid(
          source: _employeeDataSource,
          allowSorting: true,
          columns: <GridColumn>[
              GridColumn(columnName: 'id', label:Text('ID')),
              GridColumn(columnName: 'name', label:Text('Name')),
              GridColumn(columnName: 'designation', label: Text('Designation')),
              GridColumn(columnName: 'salary', label: Text('Salary')),
          ],
        ),
      ],
    ),
  );
}

Implementation

Future<void> sort() async {
  if (_dataGridStateDetails != null) {
    final DataGridConfiguration dataGridConfiguration =
        _dataGridStateDetails!();
    if (dataGridConfiguration.source.groupedColumns.isNotEmpty) {
      dataGridConfiguration.group!
          .clearDisplayElements(dataGridConfiguration);
    }
  }
  await _updateDataSource();
  _notifyDataGridPropertyChangeListeners(propertyName: 'Sorting');
}