Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UG-878952 How to improve performance when ColumnAutoSizer as Auto and SizeToCells in SfDataGrid. #1432

Open
wants to merge 3 commits into
base: hotfix/hotfix-v26.1.35
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions wpf/DataGrid/autosize-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ public class ColumnSizerExt : GridColumnSizer
{% endhighlight %}
{% endtabs %}

## Performance tips

When the [SfDataGrid.ColumnSizer](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfDataGrid.html#Syncfusion_UI_Xaml_Grid_SfDataGrid_ColumnSizer) is set to [GridLengthUnitType.Auto](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.GridLengthUnitType.html#Syncfusion_UI_Xaml_Grid_GridLengthUnitType_Auto), the column widths are calculated based on the contents of every cell in each column. But using large datasets with `ColumnSizer` as `Auto` can lead to performance issues due to the extensive calculations.

To improve the loading performance, you can use [GridColumnSizer.AutoFitMode](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html) as [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit) mode. When using both `AutoFitMode` as `SmartFit` mode with `ColumnSizer` as `Auto`, the column widths are adjusted based on the text length, but only when the current text length is greater than the previous text length.

{% tabs %} {% highlight c# %} dataGrid.GridColumnSizer.AutoFitMode = AutoFitMode.SmartFit; {% endhighlight %} {% endtabs %}

N> `AutoFitMode.SmartFit` mode does not account for special characters such as `\n` (newline) or `\t` (tab). If your `WPF DataGrid` (SfDataGrid) does not contain these special characters, we recommend enabling the Smart Fit calculation to enhance loading performance.

## Star column sizer ratio support

You can customize the `ColumnSizer.Star` width calculation logic by overriding [SetStarWidth](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.GridColumnSizer.html#Syncfusion_UI_Xaml_Grid_GridColumnSizer_SetStarWidth_System_Double_System_Collections_Generic_IEnumerable_Syncfusion_UI_Xaml_Grid_GridColumn__) method of [GridColumnSizer](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.GridColumnSizer.html).
Expand Down