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

Adding Columns asynchron

Hi there,


with your help I managed to get the columns added during runtime. Since I add alot of columns I would like to know if there is an option to update the columns asynchronously?

I have a SfDataGrid in a page. The DataContext is a ViewModel where the ColumnCollection is changed - a lot of columns are beeing added...

<syncfusion:SfDataGrid Name="dtgArbeitsvorrat"
                                           ItemsSource="{Binding Items}"
                                           SelectedItem="{Binding SelectedItem}"
                                           Columns="{Binding ColumnCollection}"
                                           AutoGenerateColumns="False" />

The colum Collection in the ViewModel looks like:

private Syncfusion.UI.Xaml.Grid.Columns _ColumnCollection;
public Syncfusion.UI.Xaml.Grid.Columns ColumnCollection
        {
            get { return _ColumnCollection; }
            set
            {
                _ColumnCollection = value;
                OnPropertyChanged("ColumnCollection");
            }
        }

When I update the columns the UI gets frozen until all columns have been added.

Is there a way to prevent the UI from beeing frozen?


Best wishes!


Victor

4 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team April 19, 2019 12:40 PM UTC

Hi Victor, 
 
Thank you for contacting Syncfusion Support. 
 
Currently we are checking on your requirement, we will validate and let you know the details in two business days April 23, 2019. We appreciate your patience until then. 
 
Regards,  
Subburaj Pandian V  



DB Dinesh Babu Yadav Syncfusion Team April 23, 2019 12:39 PM UTC

Hi Victor, 

Thanks for your patience. 

We have analyzed the reported “UI is frozen when adding columns at runtime”. But we are unable to reproduce the reported issue from our end. Please find tested sample in the below link 

Sample Link: 

If you are still facing the same issue, kindly revert us with the modified sample. It will helps us to investigate further and provide appropriate solution at earliest. 

Regards, 
Dinesh Babu Yadav. 
 



VD Victor Dienstbier April 24, 2019 11:56 AM UTC

Hi,

I tried your solution but that doesn't seem to work for me.

Within my ViewModel I have the columCollection as mentioned.

Now I try the following in the code of the page:

private ViewModel_Formular vm;
        public pagFormular()
        {
            InitializeComponent();

            vm = (ViewModel_Formular)this.DataContext;

            CreateColumnsAsync();
        }

public async void CreateColumnsAsync()
        {
            try
            {
                if (vm.ColumnCollection != null)
                {
                    vm.ColumnCollection.Clear();

                    try
                    {
                        VisualStateManager.GoToState(this.dtgArbeitsvorrat, "Busy", true);

                        dtgArbeitsvorrat.Columns.Suspend();
                        dtgArbeitsvorrat.Columns.Clear();
                        dtgArbeitsvorrat.ClearFilters();

                        await Task.Run(() => SetColumns());

                        dtgArbeitsvorrat.Columns.Resume();
                        dtgArbeitsvorrat.RefreshColumns();
                        VisualStateManager.GoToState(this.dtgArbeitsvorrat, "Normal", true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
            }
            catch (Exception)
            {

            }
        }

private void SetColumns()
        {
               vm.ColumnCollection.Add(new Syncfusion.UI.Xaml.Grid.GridImageColumn()
               {
                    HeaderText = "Test 1"
               });
               vm.ColumnCollection.Add(new Syncfusion.UI.Xaml.Grid.GridImageColumn()
               {
                    HeaderText = "Test 2"
               });
         }

Is this possible to achiev?


DB Dinesh Babu Yadav Syncfusion Team April 25, 2019 12:32 PM UTC

Hi Victor, 
 
We have analyzed the reported issue based on your provided code snippet. We are able to reproduce the reported issue with considerable amount of delay, only when more number of columns are in view. And you can resolve this by setting UseDrawing as Default for improving the loading performance. Please refer to the below UG link to know more details  
 
UG Link: 
 
If you still want to more performance improvement, please revert us with the below details 
  1. Number of columns that are shown in view area
  2. ColumnSizer that you are using
  3. SfDataGrid configuration details
If possible, kindly share the simple sample, in order to reproduce the exact delay that you are facing at our end. It will helps us to investigate further and provide appropriate solution at earlier. 
 
Regards,
Dinesh Babu Yadav.
 
 


Loader.
Live Chat Icon For mobile
Up arrow icon