Search results

Apply conditional formatting for specific row or column

You can apply conditional formatting for specific row or column using label option in the pivot grid. It can be configured using the conditionalFormatSettings option through code behind, during initial rendering. The required settings are:

  • label: Specifies the header name to apply conditions for row or column.
  • condition: Specifies the operator type such as equals, greater than, less than, etc.
  • value1: Specifies the start value.
  • value2: Specifies the end value.
  • style: Specifies the style for the cell.

To use the conditional formatting feature, You need to inject the ConditionalFormatting module in Pivot Grid.

tagHelper
LabelFormatting.cs
<ejs-pivotview id="PivotGrid"  width="100%" height="300" allowConditionalFormatting="true" showFieldList="true">
                <e-datasource data="@ViewBag.data" expandAll="false" enableSorting="true">
                    <e-formatsettings>
                        <e-field name="Amount" format="C0" maximumSignificantDigits="10" minimumSignificantDigits="1" useGrouping="true"></e-field>
                    </e-formatsettings>
                    <e-rows>
                        <e-field name="Country"></e-field>
                        <e-field name="Products"></e-field>
                    </e-rows>
                    <e-columns>
                        <e-field name="Year"></e-field>
                        <e-field name="Order_Source" caption="Order Source"></e-field>
                    </e-columns>
                    <e-values>
                        <e-field name="In_Stock" caption="In Stock"></e-field>
                        <e-field name="Sold" caption="Units Sold"></e-field>
                    </e-values>
                    <e-filters>
                        <e-field name="Product_Categories" caption="Product Categories"></e-field>
                    </e-filters>
                    <e-conditionalformatsettings>
                        <e-format label="Germany" conditions="Between" value1="500" value2="50000">
                            <e-fieldlist-style backgroundColor="#f48fb1" color="black" fontFamily="Tahoma" fontSize="12px" />
                        </e-format>
                    </e-conditionalformatsettings>
                </e-datasource>
                <e-gridSettings columnWidth="100"></e-gridSettings>
</ejs-pivotview>
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.data = data;
    return View();
}