Scaling columns with window size while using ColumnWidthMode.fitByCellValue

Hi. In my project (Windows app) I've got a DataGrid, which holds both long names and short values, so i used ColumnWidthMode.fitByCellValue to give each column the space it needs and not more, this way the the whole Grid stays visible even in a small window. 

My problem is, that when im scaling the window bigger the DataGrid doesn't scale and stays small, which looks off. 
Would it be possible to achieve a mix of .fill and .fitByCellValue so each column gets a percentage based on the CellValue and when scaling the grid the columns get scaled relative to their percentage. 


1 Reply 1 reply marked as answer

AP Abinesh Palanisamy Syncfusion Team January 2, 2025 06:27 AM UTC

Hi Jac,
 

In SfDataGrid, you can set column widths based on specific logic using the SfDataGrid.columnWidthMode or GridColumn.columnWidthMode properties. The GridColumn.columnWidthMode property allows you to define the width mode for each individual column, enabling each column to behave according to the specified columnWidthMode.


Additionally, minimumWidth and maximumWidth properties can be used to set constraints on column widths. The columnWidthMode calculates column widths while respecting the specified minimumWidth and maximumWidth values. We have provided sample for your reference. Please refer to the attached sample for more details.

Please note that if you want to ensure that content with varying lengths is not clipped, you can use the minimumWidth property to maintain a reasonable width. If you reduce the screen width too much, the grid will become scrollable. This is the expected behavior of the grid.
 

To further customize column widths, you can use the GridColumn.width property. By default, this property is not assigned any value. Using this approach, you can explicitly define the desired width for each column based on your requirements.

Please refer to the below UG documentation for more information.

UG - Column sizing & Manual width


Regards,

Abinesh P


Attachment: SfDataGrid_8ca66566.zip

Marked as answer
Loader.
Up arrow icon