sortedColumns property

List<SortColumnDetails> sortedColumns

The collection of SortColumnDetails objects to sort the columns in SfDataGrid.

You can use this property to sort the columns programmatically also. Call sort method after you added the column details in sortedColumns programmatically.

The following example show how to sort the columns on datagrid loading,

Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('Syncfusion Flutter DataGrid'),
    body: Column(
      children: [
          child: Text('Click'),
          onPressed: () {
                .add(SortColumnDetails('id', SortDirection.ascending));
          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')),

See also:


List<SortColumnDetails> get sortedColumns => _sortedColumns;