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

Conditional Formatting based on other Field

5 Answers 272 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Jan-Bernd
Top achievements
Rank 1
Jan-Bernd asked on 14 Mar 2013, 08:22 AM
Hi,

I have a PivotGrid, which has the following layout:

<telerik:RadPivotGrid ID="RadPivotGrid1" runat="server" AllowFiltering="false" RowGroupsDefaultExpanded="false"  RowTableLayout="Compact"
    ShowColumnHeaderZone="false" ShowDataHeaderZone="false" ShowFilterHeaderZone="false" ShowRowHeaderZone="false"
    OnNeedDataSource="RadPivotGrid1_NeedDataSource" OnCellDataBound="RadPivotGrid1_CellDataBound">
    <ClientSettings EnableFieldsDragDrop="false">
        <Scrolling AllowVerticalScroll="false"></Scrolling>
    </ClientSettings>
    <TotalsSettings RowsSubTotalsPosition="Last" ColumnsSubTotalsPosition="None" />
    <Fields>
        <telerik:PivotGridRowField DataField="Customer" ZoneIndex="0">
        </telerik:PivotGridRowField>
        <telerik:PivotGridRowField DataField="Contract" ZoneIndex="1">
        </telerik:PivotGridRowField>
        <telerik:PivotGridColumnField DataField="Quater">
        </telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="SalesTax">
        </telerik:PivotGridColumnField>
        <telerik:PivotGridAggregateField DataField="Amount" Aggregate="Sum">
        </telerik:PivotGridAggregateField>
        <telerik:PivotGridAggregateField DataField="Changed" Aggregate="Sum" IsHidden="true">
        </telerik:PivotGridAggregateField>
    </Fields>
</telerik:RadPivotGrid>

The AggregateField "Amount" is type of decimal and "Changed" is type of bool. 

My aim is to format the Field "Amount" with an ending "*" or a special color, if the Field "Changed" is true. How could I achieve this?


Thanks,
Jan-Bernd

5 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 19 Mar 2013, 01:01 PM
Hello Jan-Bernd,

Currently there is no easy way to format an aggregate cell depending on the value of another aggregate cell. However you can try something like this:
protected void RadPivotGrid2_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
    {
        if (e.Cell is PivotGridDataCell)
        {
            PivotGridDataCell cell = e.Cell as PivotGridDataCell;
            if (cell != null && (cell.Field as PivotGridAggregateField).DataField == "Changed")
            {
                if (Convert.ToBoolean(cell.DataItem))
                {
                    var cells = (cell.Parent as PivotGridDataItem).Cells;
                    int index = cells.Cast<PivotGridDataCell>().ToList().IndexOf(cell);
                    cells[index-1].CssClass = "YourCssClass";
                }
            }
    
        }
    }

In the example provided I am intercepting the OnCellDataBound event and checking whether the cell belongs to the Changed aggregate field. Later given the value of the cell I am assigning a CSS class to the previous cell.

Kind regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jan-Bernd
Top achievements
Rank 1
answered on 19 Mar 2013, 04:02 PM
Hello Angel,

thanks for your reply.

Your code works fine if I set the Field "Changed" to visible but if it's not, the OnCellDataBound won't get fired. I've tried to set the Changed-Field to visible and hide it by CSS-Class but it destroys the layout of the pivotgrid...

Do you have any other suggestion for me?

Thanks,
Jan-Bernd
0
Angel Petrov
Telerik team
answered on 22 Mar 2013, 01:57 PM
Hi Jan-Bernd,

I am sorry to say but the behavior you are experiencing is expected. When the Changed field is not visible the OnCellDataBound event is not suppose to fire. As for the layout problem could you please show us how are you applying the CSS and what type of problem are you experiencing? Thus we should be able to give you a suggestion on how to resolve the issue.

Kind regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Daniel
Top achievements
Rank 1
answered on 02 Jun 2016, 08:39 PM

I would like to do a very similar thing to this, except i would like to change the forecolor of the parent row (zoneindex 0) based off a field in the dataset that shown on the chart and add a tooltip to the parent field based on another field in the dataset that  on the chart.

 

is that at all possible?

0
Angel Petrov
Telerik team
answered on 07 Jun 2016, 07:59 AM
Hello,

Are you using a chart control or a pivot grid?

If you are using a pivot and the field is not visible the OnCellDataBound event will not fire thus preventing you from styling the row. Considering the aforementioned I suggest revising the requirements.

Regards,
Angel Petrov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
PivotGrid
Asked by
Jan-Bernd
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Jan-Bernd
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Share this question
or