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

How to autosize column widths in SfDataGrid?


I am trying to autosize column widths in the new SfDataGrid for Xamarin.Android (Preview), but I can't find the right option. Now my columns are fixed width and behave differently on small & large screen resolutions.

Is column autosizing not implemented yet or is there a workaround?

Regards, Michel.

3 Replies

HN Harikrishnan N Syncfusion Team April 29, 2015 12:05 PM UTC

Hi Michel,

Sorry for the inconvenience caused

At present there is no support for “Column AutoSizing”. However you can set the default column width by using the SfDataGrid.DefaultColumnWidth property or you can set the individual column’s width by handling the SfDataGrid.AutoGeneratingColumn event and by setting the Column.Width property of each column to meet your requirement. Please refer the below code snippet.

//Setting the Column width of all the columns

sfGrid.DefaultColumnWidth = 180;

sfGrid.AutoGeneratingColumn += GridAutoGenerateColumns;


void GridAutoGenerateColumns (object sender, AutoGeneratingColumnArgs e)

{

if (e.Column.MappingName == "SupplierID") {

e.Column.Width = 150;

}

/// more code for other columns
}


We have this Feature in our wish list and it will be implement in our upcoming release.

Please let us know if you have any further queries.

Regards,
Harikrishnan.



MI Michel April 29, 2015 12:18 PM UTC

Thanks for your reply Harikrishnan.

I have come up with the following solution for now:

During the column definition I first get the ScreenWidth and ScreenHeight by calling:
    App.ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels; // real pixels
    App.ScreenHeight = (int)Resources.DisplayMetrics.HeightPixels; // real pixels

Then I assign the Width of each column to a percentage of that ScreenWidth.
If the sum adds up to 100% I can be sure that it fits on the screen.

Looking forward to the next release. Is there a public wishlist available?

Regards, Michel.



HN Harikrishnan N Syncfusion Team April 30, 2015 07:26 AM UTC

Hi Michel,

Sorry, There is no public wishlist available.

Please let us know if you have any further queries.

Regards,
Harikrishnan


Loader.
Live Chat Icon For mobile
Up arrow icon