Hi
Chris,
Thanks
for your update.
If
you want to perform the sorting for multi columns, you can set the
allowMultiColumnSorting property as true. To apply sorting for multiple columns in web, you can
click the column header by pressing the CTRL
key.
|
@override Widget build(BuildContext context)
{ return Scaffold( appBar: AppBar( title:
Text(widget.title), ), body: SfDataGrid( source:
_sortingDataGridSource, allowSorting:
true, allowMultiColumnSorting:
true, columnWidthMode:
ColumnWidthMode.auto, columns:
getColumns(), ), );
} |
Currently,
if you want to perform the custom sorting for multiple columns, you should write
the logic to sort the multiple columns like we did in our SfDataGrid internally.
In the below sample, I have provided the simple example to perform the case
insensitive sorting for text columns (name and city). It also supports to apply
the sorting for other columns too.
Meanwhile,
we have a plan to expose the compare method (The method that we use to compare
the two objects) in DataGridSource class. So that, you can return the case
insensitive value for comparison in single place rather than writing entire
logic for sorting in handleSort method. We will include this in our weekly nuget
release which is scheduled on October 20th 2020.
Please
let us know if you have any concerns.
Regards,
Neelakandan
Hi Chris,
Thanks for your patience.
We will expose the compare method in
DataGridSource class. You can simply override that method and return the
value based on your requirement. Please find the example code,
|
final EmployeeDataSource _employeeDataSource =
EmployeeDataSource(); class EmployeeDataSource
extends DataGridSource<Employee>
{ @override List<Employee> get dataSource => _employees @override getValue(Employee
employee, String columnName) { switch (columnName) { case 'id': return employee.id; break; case 'name': return employee.name; break; case 'salary': return employee.salary; break; case 'designation': return employee.designation; break; default: return ' '; break; } } @override int compare(Employee value1, Employee value2,
SortColumnDetails sortColumn) { if (sortColumn.name == 'name')
{
return
value1.name.toLowerCase().compareTo(value2.name.toLowerCase());
} return super.compare(value1, value2,
sortColumn); } } |
As we mentioned, we will include this changes in our upcoming
weekly pub release. Please let us know if you have any concerns.
Regards,
Neelakandan
Hello Kannan, can I use your assistance with the Datagrid widget?
David,
Please include more details about your query. This would be helpful for us to serve you.