This is a migrated thread and some comments may be shown as answers.

Formatting Group Total

3 Answers 102 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Alessio Bulleri
Top achievements
Rank 1
Alessio Bulleri asked on 10 Apr 2019, 02:00 PM

Hi,

I need to format the text in a GroupElement calculated on a datetime field, removing the time part [I want 10/04/19 instead of 10/04/2019 00:00:00].

I found a suggestion in this forum and wrote this code :

private void rpvtGrid_GroupElementFormatting(object sender, PivotGroupElementEventArgs e) {
    object laCosa = e.GroupElement?.Data?.Group?.Name;
    if (laCosa != null && laCosa is DateTime) {
        DateTime laData = (DateTime)laCosa;
        e.GroupElement.Text = laData.ToString("dd/MM/yy") + " Total";
    }
}

 

The last line of the method assign  the correct value to e.GroupElement.Text but on the inteface nothing changes and I still see the original  text [10/04/2019 00:00:00].

What did i miss ?

[This may be someway related to my previous post.]

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 15 Apr 2019, 08:36 AM
Hi Alessio,

Thank you for writing. 

The type of the sub-totals is a string and these elements do not pass the if statement. You can try handling the event this way:  
private void RadPivotGrid1_GroupElementFormatting(object sender, PivotGroupElementEventArgs e)
{
    if (e.GroupElement.Data.Group.Type == GroupType.Subtotal)
    {
        string text = e.GroupElement.Data.Group.Parent.Name.ToString();
        DateTime date;
        if (DateTime.TryParse(text, out date))
        {
            e.GroupElement.Text = date.ToString("dd/MM/yy") + " SubTotal";
        }  
    }
 
    object laCosa = e.GroupElement?.Data?.Group?.Name;
    if (laCosa != null && laCosa is DateTime)
    {
        DateTime laData = (DateTime)laCosa;
        e.GroupElement.Text = laData.ToString("dd/MM/yy");
    }
}

I hope this will help. Let me know if you have other questions.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alessio Bulleri
Top achievements
Rank 1
answered on 15 Apr 2019, 10:14 AM

Hi Hristo, 

Thanks a lot for your answer, your code soved the problem.

I've understood my mistake and modified my code because I prefere to directly check the type than convert to string and then try to parse it.

This seems to work fine too :

private void rpvtGrid_GroupElementFormatting(object sender, PivotGroupElementEventArgs e) {
 
    object groupValue = null;
    switch (e.GroupElement.Data.Group.Type) {
        case GroupType.Subtotal:
            groupValue = e.GroupElement.Data.Group.Parent?.Name;
            break;
        case GroupType.Subheading:
        case GroupType.BottomLevel:
            groupValue = e.GroupElement.Data.Group.Name;
            break;
    }
 
    if (groupValue != null && groupValue is DateTime) {
        DateTime groupDate = (DateTime)groupValue;
        e.GroupElement.Text = groupDate.ToString("dd/MM/yy") + (e.GroupElement.Data.Group.Type == GroupType.Subtotal ? " Total" : String.Empty);
    }
}
0
Accepted
Hristo
Telerik team
answered on 16 Apr 2019, 05:16 AM
Hello Alessio,

I am glad that I managed to help. Let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PivotGrid and PivotFieldList
Asked by
Alessio Bulleri
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Alessio Bulleri
Top achievements
Rank 1
Share this question
or