allowSorting property
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:
- GridColumn.allowSorting - which allows users to sort the columns in SfDataGrid.
- sortingGestureType – which allows users to sort the column in tap or double tap.
- DataGridSource.sortedColumns - which is the collection of SortColumnDetails objects to sort the columns in SfDataGrid.
- DataGridSource.sort - call this method when you are adding the SortColumnDetails programmatically to DataGridSource.sortedColumns.
Implementation
final bool allowSorting;