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

Format GridDataItem in radPivotGrid

4 Answers 177 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 14 Apr 2015, 10:00 PM

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

4 Answers, 1 is accepted

Sort by
0
Julian
Top achievements
Rank 1
answered on 16 Apr 2015, 04:09 PM

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!!

 

 

 

0
Maria Ilieva
Telerik team
answered on 17 Apr 2015, 12:31 PM
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.

 
0
Julian
Top achievements
Rank 1
answered on 17 Apr 2015, 01:50 PM

 

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!!

 

 

 

0
Maria Ilieva
Telerik team
answered on 22 Apr 2015, 06:58 AM
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.

 
Tags
PivotGrid
Asked by
Julian
Top achievements
Rank 1
Answers by
Julian
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or