Hi Renato,
Thanks for your patience.
We have considered your requirement to refresh the column widths whenever the underlying datasource is changed. As per your update, seems you are not entirely assigning the new object to source property in SfDataGrid. You are just apply the filtering in underlying datasource and update datasource property in DataGridSource class. If you are changing the datasource in this way, we will expose the shouldRecalculateColumnWidths method in DataGridSource class in our upcoming weekly pub release which is scheduled to be published on October 27th 2020 . You can return true always or return true whenever it requires based on your requirement. By returning true, DataGrid will detect this and refresh the columnWidths whenever the notifyDataSourceListeners() or notifyListeners() method is called. Please refer the below code example,
|
class
EmployeeDataSource extends DataGridSource<Employee> { @override List<Employee> get dataSource =>
_employees; @override Object 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
bool shouldRecalculateColumnWidths() {
return true;
} } |
If you are
changing the new DataGridSource object to source property, we will provide that support as well in upcoming
weekly pub release. In this case, you don't need to override the shouldRecalculateColumnWidths method in DataGridSource.
Please let us know if this solution suits to your requirement.
Regards,
Neelakandan
We are glad to announce that our Essential
Studio 2020 Volume 3 Service Pack release v18.3.0.47 is rolled out and is
available for download under the following link.
Please refer the below UG link for the example code snippet to recalculate the column widths when datasource is changed,