Sfdatagrid group by name and id

Hi Good day,

I have my information as shown in sfdatagrid, I want to group it by Name and Count the unique Ids.

I will be expecting and output like:

Mark=2
Zed=1
Claire=1

Name     Type                         Ids
Mark     Generic - 200mm     166071
Mark     Generic - 200mm     166071
Mark     Generic - 200mm     166108
Zed       Generic - 200mm     166108
Claire    Generic - 200mm     166271
Claire    Generic - 200mm     166271

thank you

3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team May 25, 2021 10:47 AM UTC

Hi Mark, 

Thanks for contacting Syncfusion products.  

We are little unclear with your requirement. We regret for the inconvenience. Kindly revert to us with more details about your requirement with some image illustration if possible. It will be more helpful for us to understand your exact requirement and to provide a prompt solution. 

Regards, 
Mohanram A. 



MJ Mark Jayvee May 25, 2021 04:52 PM UTC

Hi,

Sorry for the confusion and failure of the description.

At Column name there are 3 Mark with 2 the same id and 1 unique.

What I what to do is to group it so that it will give me an answer like Mark have a count of 2. Which means it combines the id where there is duplicate.

Thank u


MA Mohanram Anbukkarasu Syncfusion Team May 26, 2021 01:55 PM UTC

Hi Mark, 

Thanks for the update.  

We are able to understand your requirement. SfDataGrid doesn’t have any direct support for this. However you can achieve this using sample level workaround by creating a custom renderer for the group caption as shown in the following code example.  

Code example :  

this.sfDataGrid1.CellRenderers["CaptionSummary"] = new GridCaptionSummaryCellRendererExt(); 
 
public class GridCaptionSummaryCellRendererExt : GridCaptionSummaryCellRenderer 
{ 
    protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) 
    { 
        if (cellValue.Contains("Name")) 
        { 
            var dataRow = (DataRow)column.GetType().GetProperty("DataRow", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(column); 
 
            Group group = dataRow.RowData as Group; 
 
            string ID = string.Empty; 
            int count = 0; 
 
 
            foreach (var record in group.Records) 
            { 
                if (ID == (record.Data as Data).ID) 
                    continue; 
                ID = (record.Data as Data).ID; 
                count++; 
 
            } 
 
            cellValue = "Name : " + group.Key + "-" + count.ToString() + " " + "Items"; 
        } 
 
        base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex); 
    } 
} 



Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 



Marked as answer
Loader.
Up arrow icon