From f6bd7e43df16f3e7594623417135c638e31127dd Mon Sep 17 00:00:00 2001 From: Gokul Subramani Date: Thu, 4 Jul 2024 17:43:37 +0530 Subject: [PATCH 1/3] UG-878952 How to improve performance when ColumnAutoSizer as Auto and SizeToCells in SfDataGrid --- wpf/DataGrid/autosize-columns.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wpf/DataGrid/autosize-columns.md b/wpf/DataGrid/autosize-columns.md index 7a4d43eb59..818c878819 100644 --- a/wpf/DataGrid/autosize-columns.md +++ b/wpf/DataGrid/autosize-columns.md @@ -257,6 +257,16 @@ public class ColumnSizerExt : GridColumnSizer {% endhighlight %} {% endtabs %} +## Performance tips + +By default, when using the [SfDataGrid.ColumnSizer](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfDataGrid.html#Syncfusion_UI_Xaml_Grid_SfDataGrid_ColumnSizer) property, the column widths are calculated based on the contents of every cell in each column. This comprehensive calculation can lead to performance issues. To improve the loading performance of the [WPF DataGrid](https://www.syncfusion.com/wpf-controls/datagrid) (SfDataGrid), set the [GridColumnSizer.AutoFitMode](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html) property to [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit). + +In the [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit) mode, the column widths are adjusted by measuring the text only when the current string length exceeds the previous string 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). From 1470172ad6fcd7584d80b2b1271a32e71a6bc643 Mon Sep 17 00:00:00 2001 From: Gokul Subramani Date: Thu, 4 Jul 2024 18:24:31 +0530 Subject: [PATCH 2/3] UG-878952 WPF DataGrid AutoColumnSizer performance tips was modified --- wpf/DataGrid/autosize-columns.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpf/DataGrid/autosize-columns.md b/wpf/DataGrid/autosize-columns.md index 818c878819..c7465e1040 100644 --- a/wpf/DataGrid/autosize-columns.md +++ b/wpf/DataGrid/autosize-columns.md @@ -259,9 +259,9 @@ public class ColumnSizerExt : GridColumnSizer ## Performance tips -By default, when using the [SfDataGrid.ColumnSizer](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfDataGrid.html#Syncfusion_UI_Xaml_Grid_SfDataGrid_ColumnSizer) property, the column widths are calculated based on the contents of every cell in each column. This comprehensive calculation can lead to performance issues. To improve the loading performance of the [WPF DataGrid](https://www.syncfusion.com/wpf-controls/datagrid) (SfDataGrid), set the [GridColumnSizer.AutoFitMode](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html) property to [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit). +By default, when using the [SfDataGrid.ColumnSizer](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfDataGrid.html#Syncfusion_UI_Xaml_Grid_SfDataGrid_ColumnSizer) property, the column widths are calculated based on the contents of every cell in each column. This comprehensive calculation can lead to performance issues, which is reasonable. To improve the loading performance of the [WPF DataGrid](https://www.syncfusion.com/wpf-controls/datagrid) (SfDataGrid), set the [GridColumnSizer.AutoFitMode](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html) property to [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit). -In the [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit) mode, the column widths are adjusted by measuring the text only when the current string length exceeds the previous string length. +In the [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit) mode, the column widths are measured by text only when the current text length is greater than the previous text length. Therefore, this calculation is more efficient than the `ColumnSizer`. Please be aware that this `GridColumnSizer.AutoFitMode` can result in longer calculation times, especially for larger datasets. {% tabs %} {% highlight c# %} dataGrid.GridColumnSizer.AutoFitMode = AutoFitMode.SmartFit; {% endhighlight %} {% endtabs %} From dc09c1825befdf1d8168a2ca0c707858d63165c6 Mon Sep 17 00:00:00 2001 From: Gokul Subramani Date: Thu, 4 Jul 2024 19:31:45 +0530 Subject: [PATCH 3/3] UG-878952 How to improve performance when ColumnAutoSizer as Auto and SizeToCells in SfDataGrid --- wpf/DataGrid/autosize-columns.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpf/DataGrid/autosize-columns.md b/wpf/DataGrid/autosize-columns.md index c7465e1040..7849cc9814 100644 --- a/wpf/DataGrid/autosize-columns.md +++ b/wpf/DataGrid/autosize-columns.md @@ -259,9 +259,9 @@ public class ColumnSizerExt : GridColumnSizer ## Performance tips -By default, when using the [SfDataGrid.ColumnSizer](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.SfDataGrid.html#Syncfusion_UI_Xaml_Grid_SfDataGrid_ColumnSizer) property, the column widths are calculated based on the contents of every cell in each column. This comprehensive calculation can lead to performance issues, which is reasonable. To improve the loading performance of the [WPF DataGrid](https://www.syncfusion.com/wpf-controls/datagrid) (SfDataGrid), set the [GridColumnSizer.AutoFitMode](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html) property to [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit). +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. -In the [AutoFitMode.SmartFit](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.AutoFitMode.html#Syncfusion_UI_Xaml_Grid_AutoFitMode_SmartFit) mode, the column widths are measured by text only when the current text length is greater than the previous text length. Therefore, this calculation is more efficient than the `ColumnSizer`. Please be aware that this `GridColumnSizer.AutoFitMode` can result in longer calculation times, especially for larger datasets. +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 %}