Change Column Width view

I have a DataGrid with columnWidthMode: ColumnWidthMode.cells, it populates with two different datasources depending on selection  

The data from the first Datasource is very small resulting in narrow columns, the data in the second Datasource is very long, the grid stays with the same column width as the first datasource.

The grid gets refresh with .notifyDataSourceListeners()

Thank you!

Attachment: Screenshots_3c032904.rar

6 Replies 1 reply marked as answer

BS Balasubramani Sundaram Syncfusion Team October 20, 2020 04:14 PM UTC

Hi Renato Wong,  
 
Thank you for contacting Syncfusion support, 
 
We have analysis the reported issue `ColumnWidthMode is not working while changing the data source at runtime`. We didn’t provide a support to refresh the column sizer while data source changing with same `ColumnWidthMode` and currently we are working to expose the column sizer refreshing API’s. So, we need some time to validate and update the further details and code snippet on or before 23rd October 2020.  
 
Regards,  
Balasubramani Sundaram 
 



RW Renato Wong October 20, 2020 04:20 PM UTC

Perfect, thank you for your answer.

Would be great if you can replay here once the update is live.

Thank you very much!


NK Neelakandan Kannan Syncfusion Team October 21, 2020 02:40 PM UTC

Hi Renato,

Thanks for the update.

As we promised, we will update the further details on 23/10/2020.

Regards,
Neelakandan


NK Neelakandan Kannan Syncfusion Team October 22, 2020 10:56 AM UTC

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



NK Neelakandan Kannan Syncfusion Team October 26, 2020 05:21 AM UTC

Hi Renato,

Thanks for your patience.

Due to more testing required from our end, unfortunately we couldn't move the changes in our weekly pub release which is scheduled on 27th October 2020. We will include this changes in our upcoming 2020 Volume 3 SP release which is scheduled on 3rd November 2020.

Regards,
Neelakandan


NK Neelakandan Kannan Syncfusion Team November 9, 2020 05:11 AM UTC

Hi Renato,

Thanks for your patience.

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.

 

https://www.syncfusion.com/forums/159441/essential-studio-2020-volume-3-service-pack-release-v18-3-0-47-is-available-for-download


Please refer the below UG link for the example code snippet to recalculate the column widths when datasource is changed,


https://help.syncfusion.com/flutter/datagrid/autofit-columns#recalculating-column-widths-when-datasource-is-changed

Marked as answer
Loader.
Up arrow icon