▦K2 Advanced GridsDeveloper Portal / 0.24
Documentation / Data presentation

Conditional formatting

Use business rules to highlight important values, status badges and critical orders directly in the existing grid.

Status badges

Continue from Boolean formatting. Each status uses an equality rule and a dedicated color.

K2AdvancedGridsConfig.defaults.conditionalFormatting = {
    "enabled": true,
    "rules": [
        {
            "column": "Status",
            "operator": "eq",
            "value": "Draft",
            "style": {
                "badge": true,
                "background": "#F1F5F9",
                "color": "#475569"
            }
        },
        {
            "column": "Status",
            "operator": "eq",
            "value": "Pending Approval",
            "style": {
                "badge": true,
                "background": "#FEF3C7",
                "color": "#92400E"
            }
        },
        {
            "column": "Status",
            "operator": "eq",
            "value": "Approved",
            "style": {
                "badge": true,
                "background": "#DCFCE7",
                "color": "#166534"
            }
        },
        {
            "column": "Status",
            "operator": "eq",
            "value": "Partially Delivered",
            "style": {
                "badge": true,
                "background": "#E0E7FF",
                "color": "#4338CA"
            }
        },
        {
            "column": "Status",
            "operator": "eq",
            "value": "Delivered",
            "style": {
                "badge": true,
                "background": "#DBEAFE",
                "color": "#1D4ED8"
            }
        },
        {
            "column": "Status",
            "operator": "eq",
            "value": "Overdue",
            "style": {
                "badge": true,
                "background": "#FEE2E2",
                "color": "#B91C1C"
            }
        },
        {
            "column": "Status",
            "operator": "eq",
            "value": "Cancelled",
            "style": {
                "badge": true,
                "background": "#E5E7EB",
                "color": "#6B7280"
            }
        }
    ]
};
K2AdvancedGrids.instance.refresh();
Download status configuration ↓
Required after saving a configuration file

Replace REPLACE_WITH_YOUR_AREAITEMID with your own ID (see Grid Discovery). Rename the downloaded file to purchase-orders.config.js or update the loader path. Update configVersion in the Data Label (e.g. 0.7.1), save the form and reopen Runtime. Keep engineVersion unchanged. Console-only changes do not require a version change.

Seven status badges
Figure 62 · Seven status badges · Actual K2 Runtime capture

Numeric formatting

Red negative values and green positive values describe the sign only; choose business-specific semantics in production.

K2AdvancedGridsConfig.defaults.conditionalFormatting.rules.push({
    "column": "Budget Variance",
    "operator": "lt",
    "value": 0,
    "style": {
        "color": "#DC2626",
        "fontWeight": "600"
    }
},
{
    "column": "Budget Variance",
    "operator": "gt",
    "value": 0,
    "style": {
        "color": "#15803D",
        "fontWeight": "600"
    }
});
K2AdvancedGrids.instance.refresh();
Signed budget variance
Figure 63 · Signed budget variance · Actual K2 Runtime capture

Cell formatting

Highlight order amounts of at least 150,000 SAR. Sort descending and navigate to the threshold.

K2AdvancedGridsConfig.defaults.conditionalFormatting.rules.push({
    "column": "Order Amount",
    "operator": "ge",
    "value": 150000,
    "style": {
        "background": "#EDE9FE",
        "color": "#5B21B6",
        "fontWeight": "700"
    }
});
K2AdvancedGrids.instance.refresh();
High-value cells
Figure 64 · High-value cells · Actual K2 Runtime capture

Row formatting

Highlight urgent orders with a pale orange background.

K2AdvancedGridsConfig.defaults.conditionalFormatting.rules.push({
    "column": "Is Urgent",
    "operator": "eq",
    "value": true,
    "style": {
        "background": "#FFF7ED"
    },
    "target": "row"
});
K2AdvancedGrids.instance.refresh();
Urgent rows
Figure 65 · Urgent rows · Actual K2 Runtime capture

Multiple conditions and priority

Urgent AND Overdue receives a higher-priority red background. The first matching rule for each style property wins within the row or cell target; cell properties override row properties. Status badge cells may retain their ordinary cell background because the badge background is applied to the inner text.

K2AdvancedGridsConfig.defaults.conditionalFormatting.rules.push({
    "target": "row",
    "logic": "and",
    "priority": 100,
    "conditions": [
        {
            "column": "Status",
            "operator": "eq",
            "value": "Overdue"
        },
        {
            "column": "Is Urgent",
            "operator": "eq",
            "value": true
        }
    ],
    "style": {
        "background": "#FEE2E2"
    }
});
K2AdvancedGrids.instance.refresh();
Critical rows and individual cell styles
Figure 66 · Critical rows and individual cell styles · Actual K2 Runtime capture
Download combined configuration ↓
Offline AND / OR playground

Date-based formatting

The isolated date rule was verified in K2 Runtime: 22 and 17 November are highlighted for Overdue orders, while past Delivered dates and future dates are not. Combined interaction with other conditional rules remains to be verified. The engine supports beforeToday and notIn (case insensitive operator names). Test independently of row backgrounds; use the following replacement rule set, rather than appending it, to make the effect visible. On 28 November 2026, PO-2026-00004 (22 November, Overdue) should match; PO-2026-00006 (20 November, Delivered) should not. The actual result depends on the browser date and SmartObject type.

K2AdvancedGridsConfig.defaults.conditionalFormatting = {
    "enabled": true,
    "rules": [
        {
            "target": "cell",
            "targetColumn": "Expected Delivery Date",
            "logic": "and",
            "conditions": [
                {
                    "column": "Expected Delivery Date",
                    "operator": "beforeToday"
                },
                {
                    "column": "Status",
                    "operator": "notIn",
                    "value": [
                        "Delivered",
                        "Cancelled"
                    ]
                }
            ],
            "style": {
                "background": "#FEE2E2",
                "color": "#B91C1C",
                "fontWeight": "700"
            }
        }
    ]
};
K2AdvancedGrids.instance.refresh();
Download isolated date test ↓
Verified isolated date-cell highlight
Figure 67 · Verified isolated date-cell highlight · Actual K2 Runtime capture

Combined features

Restore the combined rule set. Filter Status = Overdue and Is Urgent = Yes. The actual Runtime capture shows 50 matching orders, total 5,940,175.22, average 118,803.50 and budget variance 2,603.60. The page size is 10 and five pages remain.

Filtered critical orders and recalculated KPI
Figure 68 · Filtered critical orders and recalculated KPI · Actual K2 Runtime capture

Configuration reference

ParameterBehavior
enabled / rulesEnable module and declare rules; individual enabled:false skips a rule.
column / targetColumnCondition column; optional separate cell target.
targetrow or cell (default cell).
operatoreq, ne, gt, ge, lt, le, between, blank, notblank, in, notin, contains, notcontains, starts, ends, beforetoday, aftertoday, today.
value / valueToComparison operand(s); between also accepts a two-element array. in/notin require arrays.
conditions / logicNested conditions; or means any; otherwise all (AND). Empty conditions do not match.
priorityHigher numeric priority first; equal priority follows declaration order.
stopIfTrueStop processing further rules for that row after a match.
stylebackground, color, fontWeight, fontStyle, textDecoration, badge, alignment.

Benefits and limitations

Formatting is client-side over loaded records, not a server policy. Date operators require Date or DateTime; text operators require compatible text types. Badges require a simple standard text cell and do not replace Boolean formatting. Pinning, native View Details, OR behavior and refresh were not independently verified by these captures. Use the combined configuration as the baseline for the next lesson.

Enlarged screenshot