sortedColumns property
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,
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Syncfusion Flutter DataGrid'),
),
body: Column(
children: [
TextButton(
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')),
],
),
],
),
);
}
See also:
SfDataGrid.allowSorting
– which allows users to sort the columns inSfDataGrid
.GridColumn.allowSorting
- which allows users to sort the corresponding column inSfDataGrid
.DataGridSource.sort
- call this method when you are adding theSortColumnDetails
programmatically toDataGridSource.sortedColumns
.
Implementation
List<SortColumnDetails> get sortedColumns => _sortedColumns;