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.
Unfortunately, activation email could not send to your email. Please try again.

Group label format

Thread ID:

Created:

Updated:

Platform:

Replies:

119344 Jun 8,2015 10:29 AM Jun 10,2015 07:55 AM Windows Forms 3
loading
Tags: GridGroupingControl
Felipe Bahiana Almeida
Asked On June 8, 2015 10:29 AM

I have one grid that has one datetime column. 
When I try to use this column, to group itens related, this is showing date in format "dd/MM/yyyy hh:mm:ss AM/PM" in the group label.
I want to be able to format these values acording to my users (MMM-yy) and make syncfusion group itens in the same month/year.

(I tried to create one adictional column of type string that contais that value, but the problem is that the sort is messed up.

Thanks

Attachment: print_186e85ce.zip

Solai A L [Syncfusion]
Replied On June 9, 2015 01:31 AM

Hi Felipe,

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:
http://www.syncfusion.com/downloads/support/forum/119344/ze/WindowsFormsApplication21_(7)-309227890



Thanks & Regards,
AL.Solai


Felipe Bahiana Almeida
Replied On June 9, 2015 08:33 AM

Thanks Solai, your example is good but there is one part missing.
Note that the sort order is wrong. We must see dates in this format but order by the Date values, not by string values.


Solai A L [Syncfusion]
Replied On June 10, 2015 07:55 AM

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:

http://www.syncfusion.com/downloads/support/forum/119344/ze/WindowsFormsApplication21_(8)-983861376


Please let us know if you have any other concerns.


Thanks & Regards,

AL.Solai.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;