RadPivotGrid Calculated Item

9 posts, 0 answers
  1. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 02 Jul 2014 Link to this post

    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.
  2. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 06 Jul 2014 Link to this post

    Is there anyway I can update the dataformatstring of a specific cell, row/column dependent on the e.GroupName.ToString()?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 07 Jul 2014 Link to this post

    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.

     
  5. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 07 Jul 2014 in reply to Angel Petrov Link to this post

    Thanks Angel,

    That's a perfect solution to my problem.

    Cheers!
  6. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 07 Jul 2014 in reply to Tim Link to this post

    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.
  7. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 08 Jul 2014 in reply to Angel Petrov Link to this post

    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.
  8. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 08 Jul 2014 in reply to Angel Petrov Link to this post

    Any reference document that I can take a look on? Much appreciated.
  9. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 10 Jul 2014 Link to this post

    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.

     
  10. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 16 Jul 2014 in reply to Angel Petrov Link to this post

    Thank you very much!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017