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

RadPivotGrid Calculated Item

8 Answers 87 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 02 Jul 2014, 04:07 PM
Hi All,

Is there any possible way to set dataformatstring of a Calculated Item? I am customising the calculation behind the C# code and would like to format it into {0:p0}.

Right now, e.CalculatedValue is a double without any format.

Many thanks.

8 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 06 Jul 2014, 01:18 PM
Is there anyway I can update the dataformatstring of a specific cell, row/column dependent on the e.GroupName.ToString()?
0
Angel Petrov
Telerik team
answered on 07 Jul 2014, 12:43 PM
Hello Tim,

In order to change a row, column or a cell value you can subscribe to the OnCellDataBound event, extract the old value, format it in the described manner and set the formatted value as current. If you need to format the values according to the column or row header texts you can use the ParentColumnIndexes and ParentRowIndexes and check to which row/column does the cell belong. For example:

C#:
protected void RadPivotGrid1_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
    {
        PivotGridDataCell cell = e.Cell as PivotGridDataCell;
        if (cell != null)
        {
 
            if (cell.ParentColumnIndexes.Contains("ParentColumnValue"))
            {
                string currentValue=cell.Text;
                cell.Text = currentValue + " is modified";
            }
 
            if(cell.ParentRowIndexes.Contains("ParentRowValue"))
            {
                string currentValue = cell.Text;
                cell.Text = currentValue + " is modified";
            }
        }
    }
The above code will modify the text of the cells which belong to a column with ParentColumnValue set as header text or row with ParentRowValue used as header text.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tim
Top achievements
Rank 1
answered on 07 Jul 2014, 03:04 PM
Thanks Angel,

That's a perfect solution to my problem.

Cheers!
0
Tim
Top achievements
Rank 1
answered on 07 Jul 2014, 03:40 PM
Last question, while the cell.ParentColumnIndexes and its row counterparts are working perfect for normal radpivotgird cell, for calculated fields, the ParentColumnIndexes/ParentRowIndexes are object {Telerik.Web.UI.RadPivotGrid.GeneralCalcualtedItem} but not normal string. And therefore the Contains is not reading my header text.

Any suggestion of what if clause I should use? Thanks.
0
Tim
Top achievements
Rank 1
answered on 08 Jul 2014, 10:21 AM
While the cell.ParentColumnIndexes/ParentRowIndexes are working perfect for normal radpivotgird cell, for calculated fields, the ParentColumnIndexes/ParentRowIndexes are object {Telerik.Web.UI.RadPivotGrid.GeneralCalcualtedItem} but not normal string object. And therefore the Contains method is not reading my header text.

Any suggestion of what if clause condition should I use? Thanks.
0
Tim
Top achievements
Rank 1
answered on 08 Jul 2014, 03:28 PM
Any reference document that I can take a look on? Much appreciated.
0
Angel Petrov
Telerik team
answered on 10 Jul 2014, 02:44 PM
Hi Tim,

Actually you should be able to integrate the same approach for the calculated fields. By traversing the ParentColumnIndexes and ParentRowIndexes collections and calling .ToString() you should be able to extract the header values. An example on to achieve this is available in the code snippet below.

C#:
protected void RadPivotGrid1_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
        {
            PivotGridDataCell cell = e.Cell as PivotGridDataCell;
            if (cell != null && cell.CellType == PivotGridDataCellType.DataCell)
            {
                foreach (object parentColumn in cell.ParentColumnIndexes)
                {
                    string columnValue=parentColumn.ToString();
                    if(columnValue=="Forecast for 1999")
                    {
                        cell.Text = "Changed";
                    }
                }
            }
        }

Please note that we will do our best to include such an example in the documentation as soon as possible.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tim
Top achievements
Rank 1
answered on 16 Jul 2014, 04:49 PM
Thank you very much!
Tags
PivotGrid
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or