We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How can I correctly size dynamically added grid columns.


I have an SfDataGrid whose columns are dynamically added.  When there is an auto-suggest control in the cell I would like it to remain as wide as the text in the dropdown box (so the dropdown text is readable).  See attached screenshot.  They seem to always size into equal sections regardless of the ColumnSizer setting.

Also, other columns are numeric, but have multi-word names.  I'd like the header text to wrap the individual words so the column size can be decreased to fit the number.

I have tried setting ColumnSizer on the datagrid declaration, but the columns seem to remain equally sized across the grid.  Another idea, I could use the * and 2* to specify the width, but I can't figure out how to set the star-widths on the GridTextColumns (width only allows numerics).

Any advice would be appreciated!

Attachment: uglygrid_6c8f81e8.zip

1 Reply

JG Jai Ganesh S Syncfusion Team April 21, 2016 01:24 PM UTC

Hi Deanna,


Query 1:

You can achieve your requirement by customizing the GridColumnSizer and overrides the CalculateCellsWidth method.


KB Link: https://www.syncfusion.com/kb/5972/how-to-customize-the-width-of-the-gridcomboboxcolumn-based-on-its-headertext-and-items


Query 2:


You can achieve your requirement for calculating the star width for a column by customizing the ColumnSizer. We already have a kb regarding this and please find the kb link as below,


Kb Link:

                                              

https://www.syncfusion.com/kb/6081/how-to-customize-star-columnsizer-to-calculate-width-with-different-ratios-in-sfdatagrid


Regards,

Jai Ganesh S


Loader.
Live Chat Icon For mobile
Up arrow icon