Group label format
Attachment: print_186e85ce.zip
Thank you for using Syncfusion products.
To change the value of Caption label after grouping, you can use QueryCellInfo event. In this event you can customize the Caption Row cellvalue as per you requirement. The format for column will be applied only when the cellvaluetype is in corresponding type. Please refer the below image for reference. Also the below code and sample for further clarification. If your requirement is different from this please let us know with a brief explanation.
Code Snippet[c#]:
this.gridGroupingControl1.TableDescriptor.Columns["Date"].Appearance.AnyCell.CellValueType = typeof(DateTime);
this.gridGroupingControl1.TableDescriptor.Columns["Date"].Appearance.AnyCell.Format = "MMM-yyyy";
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell && e.TableCellIdentity.GroupedColumn != null)
{
GridCaptionRow captionRow = e.TableCellIdentity.DisplayElement as GridCaptionRow;
string date="";
DateTime dt;
if (e.Style.Text != null && DateTime.TryParse(e.Style.Text.Substring(e.Style.Text.IndexOf(":") + 1, 8),out dt))
{
date = dt.ToString("MMM-yyyy");
}
e.Style.CellValue = String.Format("{0}: {1} Items.", date, e.TableCellIdentity.DisplayElement.ParentGroup.GetChildCount());
}
}
Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/WindowsFormsApplication21_(7)-3092278901853385473.zip
Thanks & Regards,
AL.Solai
Hi Felipe,
Sorry for the inconvenience.
By default our grid grouping control support only string sorting. For your case you need to use Custom sorting using IComparer and handle that in SortedColumns.Changing event with the following code. Please refer the below sample and code snippet for further clarification.
Code Snippet[c#]:
gridGroupingControl1.TableDescriptor.SortedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(SortedColumns_Changing);
void SortedColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
{
SortColumnDescriptor sd = e.Item as SortColumnDescriptor;
if (sd != null && e.Action == Syncfusion.Collections.ListPropertyChangedType.Add)
{
Type type = this.gridGroupingControl1.TableDescriptor.Columns[sd.Name].Appearance.AnyRecordFieldCell.CellValueType;
if (sd.Name == "Date" && type == typeof(DateTime))
sd.Comparer = new DateComparer();
}
}
public class DateComparer : IComparer
{
public DateComparer() { }
public int Compare(object x, object y)
{
DateTime value1 = DateTime.Parse(x.ToString());
DateTime value2 = DateTime.Parse(y.ToString());
return DateTime.Compare(value1,value2);
}
}
Sample:
Please let us know if you have any other concerns.
Thanks & Regards,
AL.Solai.
- 3 Replies
- 2 Participants
-
FB Felipe Bahiana Almeida
- Jun 8, 2015 02:29 PM UTC
- Jun 10, 2015 11:55 AM UTC