Format GridDataItem in radPivotGrid

5 posts, 0 answers
  1. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 14 Apr 2015 Link to this post

    I have a regular radGrid where I do some data formatting for localization.

     I want to get at the GridDataItem like so:

    protected void OnItemDataBound(object sender, GridItemEventArgs e)
           {
               // We need to make sure empty entries are intialized to 0.00 and are set to the correct currency symbol
               if (e.Item is GridDataItem)
               {
                   GridDataItem item = (GridDataItem)e.Item;
                   FormatItem(item);

    I know that a radPivotGrid does not have an OnItemDataBound event. I'm also not certain there is an event that receives the GridItemEventArgs?

    It seems like the path I may want to take is to get at the individual cells within the pivot grid. Perhaps through the radPivotGrid1_OnCellDataBound event.

    This event receives -> PivotGridCellDataBoundEventArgs

    So my question is this. Am I on the right path? If I want to iterate the grid and format the numerical data how would I go about getting at the actual cell?

     Thanks,

    julian

  2. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 16 Apr 2015 in reply to Julian Link to this post

    I wanted to add that I am able to access the data at the cell level inside the OnPivotGridCellExporting as seen below:

     

    protected void radPivotGrid1_OnPivotGridCellExporting(object sender, PivotGridCellExportingArgs e)
            {
                var modelDataCell = e.PivotGridModelCell;
     
                var cell = e.ExportedCell;
                var table = cell.Table;
     
                if (modelDataCell != null)
                {
                    if (modelDataCell.Field != null)
                    {
                        if (IsModelDataCellPlannedValue(modelDataCell))
                        {
     
                            var cellValue = cell.Value;
                            // Properly format planned value for Excel Export
                            modelDataCell.Field.DataFormatString = "{0:#,##0.00;(#,##0.00)}";
                            modelDataCell.Field.TotalFormatString = "{0:#,##0.00;(#,##0.00)}";
                            
                        }
                    }
     
                    AddStylesToDataCells(modelDataCell, e);
                }
     

     The problem here is that the modelDataCell.Field.DataFormatString seems to do nothing.

    I need to define the numberFormat that the exported excel file utilizes for cells which have numerical data?

     

    Please help!! How do I do this.

     

    Thanks!!

     

     

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Apr 2015 Link to this post

    Hi Julian,

    You can set the data format to the ExportedCell directly as demonstrated in the online demo below:

    http://demos.telerik.com/aspnet-ajax/pivotgrid/examples/exporting/defaultcs.aspx

    Regards,
    Maria Ilieva
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 17 Apr 2015 in reply to Maria Ilieva Link to this post

     

    Maria,

     Thanks I did review that demo and I resolved this issue. I had planned on posting here to that effect but you beat me to it.

     What I wanted to do was format the numeric values in the exported grid with the current server's localized currencies. 

     What was eluding me, and I don't know why, as your demo clearly lists e.ExportedValue.Style, was how to set the ExportedCell's numberFormat. This code below actually worked out for me setting the numeric values to the current server's localization. So basically something like I have shown or e.ExportedCell.Value.FormatString(....

    try
                {
                    if (e.ExportedCell.Value != null)
                    {
                        if (String.IsNullOrEmpty(e.ExportedCell.Value.ToString()))
                        {
                            e.ExportedCell.Value = 0.00;
                        }
                    }
                    else
                    {
                        e.ExportedCell.Value = 0.00;
                    }
     
                    var cellValue = (double) e.ExportedCell.Value;
     
                    // Get current systems localization name
                    // fr-FR = French (France)
                    // fr-CA = French (Canada)
                    // en-US = English (United States)
                    // de-DE = German (Germany)
                    var currentCulture = new CultureInfo(CultureInfo.CurrentCulture.Name);
     
                    // Test code to test german formatting of the data
                    var german = new CultureInfo("de-DE");
                    currentCulture = german;
     
                    var resultString = cellValue.ToString("n", currentCulture);
                    return resultString;
                }
                catch (Exception ex)

     

     Thanks!!

     

     

     

  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 22 Apr 2015 Link to this post

    Hi Julian,

    I'm glad to hear that you were able to fix the issue using the proposed online demo. Do let us know if further assistance is needed.

    Regards,
    Maria Ilieva
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017