Is there a way to calculate the height of the DataGrid dynamically based on the content within if the datasource is finite? Now without constraint the DataGrid is default to be 300 in height, can the grid use the total of all rows' height as the grid height?
You can achieve your requirement by setting the shrinkWrapRows property as true. It sets the height based on the number of rows available in DataGrid. Please check the following code snippet.
Code snippet:
|
@override Widget build(BuildContext context) { return Scaffold( body: ListView( children: [ SfDataGrid( shrinkWrapRows: true, columnWidthMode: ColumnWidthMode.fill, source: _dataTable, columns: _columns), ], ), ); } |
We have already provided examples in our UG documentation. Please go through this,
UG Documentation: https://help.syncfusion.com/flutter/datagrid/scrolling#set-height-and-width-of-datagrid-based-on-rows-and-columns-available
We hope this helps and please let us know if you need any further assistance.
Regards,
Tamilarasan
Hi,
Thank you for your reply, this property helps solve my case. However, there are scenarios where the grid will not extend to its full height until I click on column resizing. This seems to happen when the width of the Grid is larger than the viewport aka when a horizontal scroll appears. Is there a way to fix it?
We are a little bit unclear about your requirement. Can you please provide more details about your requirement? It would be helpful if you provided a screenshot representation of your expectations. Also, please check the following sample and it’s working fine on our side. If possible, please modify the below sample for better understanding.
Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sample1521029837
Regards,
Tamilarasan
Hi, I've attached the sample file for the scenario where while DataGrid doesn't expand to its calculated height until there's a setState called, in this case when you resize column width. Also, this is on Flutter web
Attachment: Example_a507ace2.zip
We have checked your reported issue and logged this as a bug. We will include the changes in our upcoming weekly pub release which is scheduled to be rolled out on May 03, 2022. We will let you know once it gets rolled out. We appreciate your patience until then. You can follow up with the below feedback for further details,
Feedback Link: https://www.syncfusion.com/feedback/34332/datagrid-is-not-extended-to-its-maximum-height-when-setting-the-shrinkwraprows-to
Regards,
Tamilarasan
Hi Even,
Thank you for your patience.
We are glad to inform you that the fix has been included in our weekly pub release. Please update DataGrid package to 20.1.52 version.
Please let us know if you need further assistance on this.
Regards,
Ashok K