Group by on Binding of to List<Dictionary<,>>

Good day,

I am trying to implement grouping on a list of dictionary items following the example: sfdatagrid-dynamically-with-json-data

With the below code is still POC code so it is not 100% , but this code should be working.

                tapgroupBy.Tapped += (sender, args) =>
                {
                    if (viewModel != null)
                        try
                        {
                            grid.BatchBegin();                           
                            grid.View.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;
                            grid.GroupCaptionTextFormat = "{ColumnName} : {Key}";
                            (viewModel as BaseViewModel).IsBusy = true;
                            var columnName = !string.IsNullOrEmpty(column.LookupGridDisplayColumnName)
                                          ? column.LookupGridDisplayColumnName
                                          : !string.IsNullOrEmpty(column.LookupDisplayColumnName)
                                              ? column.LookupDisplayColumnName
                                              : !string.IsNullOrEmpty(column.ColumnNameAlternate)
                                                  ? column.ColumnNameAlternate
                                                  : column.ColumnName;
                            if (sender is Image imageFilter)
                            {
                               if (grid != null)
                                {
                                   
                                    if (grid.GroupColumnDescriptions.Any(a=>a.ColumnName == columnName))
                                    {
                                       // grid.GroupColumnDescriptions.Remove((grid.GroupColumnDescriptions.FirstOrDefault(a => a.ColumnName == columnName)));
                                    } else
                                    {
                                        grid.GroupColumnDescriptions.Add(new GroupColumnDescription
                                        {
                                            //ColumnName = "Values[" + columnName + "]"
                                            ColumnName = columnName,
                                           
                                          
                                        }
                                        );
                                    }                                   
                                }
                            }

                        }
                        finally
                        {
                            grid.BatchCommit();
                            if (grid.GroupColumnDescriptions.Any())
                                grid.CollapseAllGroup();
                            (viewModel as BaseViewModel).IsBusy = false;
                        }

                };

No Grouping happens on the control, what am I missing or is it not possible to do grouping?




2 Replies

CM Corrie Meyer October 3, 2018 08:53 AM UTC

Any one ?


VR Vigneshkumar Ramasamy Syncfusion Team October 3, 2018 12:46 PM UTC

  
Hi Corrie, 
 
Thanks for contacting Syncfusion Support. 
 
We checked your query of grouping is not occured, from the code example shared, we are able to get that you have not refreshed your Column to be grouped before applying Grouping. 
It is necessary to Refresh the Column, before it is grouped. Please find the code snippet of the same below. 
 
private void GroupButton_Clicked(object sender, EventArgs e) 
            { 
                //Need to refresh the GroupProperty of DynamicModel in the given collection before applying groupdescription to the grid. 
                viewModel.RefreshGroup("FirstName"); 
                grid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "GroupProperty" } 
                ); 
            } 
//ViewModel.cs 
public void RefreshGroup(string key) 
            { 
                foreach (var dynamicItem in this.DynamicCollection) { dynamicItem.RefreshGroupProperty(key); } 
            } 
//DynamicModel.cs 
public void RefreshGroupProperty(string key) 
            { 
                object value = null; 
                this.Values.TryGetValue(key, out value); 
                this.GroupProperty = value; 
            } 
Please refresh the group before applying grouping. 
 
We have attached the sample in which the column is refreshed before applying grouping, you can download the same from the below link. 
 
 
 
Regards,
Vigneshkumar R 


Loader.
Up arrow icon