Formatting Group Total

4 posts, 2 answers
  1. Alessio Bulleri
    Alessio Bulleri avatar
    34 posts
    Member since:
    Sep 2008

    Posted 10 Apr 2019 Link to this post

    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.]

     

  2. Answer
    Hristo
    Admin
    Hristo avatar
    1522 posts

    Posted 15 Apr 2019 Link to this post

    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.
  3. Alessio Bulleri
    Alessio Bulleri avatar
    34 posts
    Member since:
    Sep 2008

    Posted 15 Apr 2019 in reply to Hristo Link to this post

    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);
        }
    }
  4. Answer
    Hristo
    Admin
    Hristo avatar
    1522 posts

    Posted 16 Apr 2019 Link to this post

    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.
Back to Top