Order by count records when is grouped

Hello,
When I use dragDropArea. SFdataGrid create grouped rows. Is posible set order by count(rows in group) ?
please look attachment. 
Thank you
Vk

Attachment: example_139ea14d.zip

8 Replies

DM Dhanasekar Mohanraj Syncfusion Team December 10, 2020 12:35 PM UTC

Hi Vaclav Kure,

 
Thank you for using Syncfusion Controls.

 
Based on provided information’s we have checked the requested scenario. We don’t have a direct support to sort the records by count. You can achieve this by SfDataGrid.SortComparers like below,

 
this.sfDataGrid.SortComparers.Add(new Syncfusion.Data.SortComparer() { Comparer = new CustomComparer(), PropertyName = "Country" }); 

public
class CustomComparer : IComparer<object>, ISortDirection 
{ 
    public int Compare(object x, object y) 
    { 
        string nameX; 
        string nameY; 
 
        //While data object passed to comparer 
        if (x.GetType() == typeof(OrderInfo)) 
        { 
            nameX = ((OrderInfo)x).Country; 
            nameY = ((OrderInfo)y).Country; 
 
            if (nameX.CompareTo(nameY) > 0) 
                return SortDirection == ListSortDirection.Ascending ? 1 : -1; 
 
            else if (nameX.CompareTo(nameY) == -1) 
                return SortDirection == ListSortDirection.Ascending ? -1 : 1; 
 
            else 
                return 0; 
        } 
        //While sorting groups 
        else if (x.GetType() == typeof(Group)) 
        { 
            int countX; 
            int countY; 
 
            //Calculating the group key length 
            countX = ((Group)x).Source.Count; 
            countY = ((Group)y).Source.Count; 
 
            if (countX.CompareTo(countY) > 0) 
                return SortDirection == ListSortDirection.Ascending ? 1 : -1; 
 
            else if (countX.CompareTo(countY) == -1) 
                return SortDirection == ListSortDirection.Ascending ? -1 : 1; 
 
            else 
                return 0; 
        } 
        return 0; 
    } 
    private ListSortDirection _SortDirection; 
 
    /// <summary> 
    /// Gets or sets the property that denotes the sort direction. 
    /// </summary> 
    /// <remarks> 
    /// SortDirection gets updated only when sorting the groups. For other cases, SortDirection is always ascending. 
    /// </remarks> 
    public ListSortDirection SortDirection 
    { 
        get { return _SortDirection; } 
        set { _SortDirection = value; } 
    } 
} 

We have prepared the sample for the same.

 
 
 
Please refer the below user guide documentation for more information’s 

 
We hope it helps, please let us know if you need further assistance. 

Regards,
Dhanasekar Mohanraj. 



VK Vaclav Kure December 11, 2020 08:52 AM UTC

Thank you for your answer.
Your example work well, when columns in colection are known:
this.sfDataGrid.SortComparers.Add(new Syncfusion.Data.SortComparer() { Comparer = new CustomComparer(), PropertyName = "Country" }); 
Property name is known, when project is compiling...
there is some way, how to set ordering in counts in group when datasource is unknown? 
             DataTable dataTable = new dataTable();
            dataTable = DataMiner.GetDataByNumber(1);      //return different table by parametr ()   
            sfDataGrid1.DataSource = dataTable;
I need sorting by count in groups for all columns. And for one sfDataGrid with difference dataSource.
I created example in attach.
Thank you
Vk

Attachment: CustomSort_978c1c64.zip


DM Dhanasekar Mohanraj Syncfusion Team December 14, 2020 12:56 PM UTC

Hi Vaclav Kure,

 
Thank you for your response.

 
We are currently working on this we will check and update with further details on December 16,2020. 

We will appreciate your patience until then. 

Regards,
Dhanasekar Mohanraj. 



DM Dhanasekar Mohanraj Syncfusion Team December 16, 2020 01:20 PM UTC

Hi Vaclav Kure,

 
Sorry for the inconvenience caused.

 
Currently, we are checking the feasibility to achieve your requirement. We will validate and update you the details on December 18,2020.

 
We will appreciate your patience until then.

 
Regards,
Dhanasekar Mohanraj.  



DM Dhanasekar Mohanraj Syncfusion Team December 18, 2020 04:21 PM UTC

Hi Vaclav Kure,

 
 
We are still working on this we will update further details on December 22,2020. 
 
We will appreciate your patience until then. 
   
Regards,   
Dhanasekar Mohanraj.  


DM Dhanasekar Mohanraj Syncfusion Team December 22, 2020 02:09 PM UTC

Hi Vaclav Kure, 

Sorry for the inconvenience caused. 

We are still working on this we will update further details on December 24, 2020. 

We appreciate your patience until then.

 
Regards, 
Dhanasekar Mohanraj. 



MA Mohanram Anbukkarasu Syncfusion Team December 24, 2020 02:39 PM UTC

Hi Vaclav Kure,     
 
Sorry for the inconvenience.    
 
As it requires more analysis in our end we are unable to provide details as promised. We are still working on this. We will update with further details on December 29, 2020. We appreciate your patience and understanding.   
 
Regards,     
Mohanram A.  
  



DM Dhanasekar Mohanraj Syncfusion Team December 29, 2020 03:55 PM UTC

Hi Vaklav Kure, 

Thank you for your patience. 

In Sfdatagrid, when grouping is applied, the data is organized into a hierarchical structure based on matching column values and it is sorted by ascending order. 
You can achieve your requirement using SortComparer as our previous response. You can get this same behavior for all columns but it allow’s only one group at a time when you grouped the second column application crashed. 

 
Note: There is no possible ways to add SortComparers for all columns in the same time. 

Please let us know if you have any other queries. 
 
Regards,
Dhanasekar Mohanraj.


Loader.
Up arrow icon