Reputation: 133
This question is actually sort of simple, but: Is it possible to sort a DataTable on more than one column? So that the user can decide if it should be sorted on for example Name or Year?
If possible how do you implement it?
Upvotes: 1
Views: 2434
Reputation: 1960
you can use onSort in every column like this
DataColumn(
label: Text('name'),
onSort: (columnIndex, sortAscending) {
setState(() {
if (columnIndex == _sortColumnIndex) {
_sortAsc = _sortNameAsc = sortAscending;
} else {
_sortColumnIndex = columnIndex;
_sortAsc = _sortNameAsc;
}
_persons.sort((a, b) => a.name.compareTo(b.name));
});
},
),
Upvotes: 1