Menu
Download Free Trial
Table of contents

addCondition

addCondition(condition:Conditional Format Object)

[starting from version: 1.5]

Adds a conditional formatting rule for cell values to format them with specific styles if the condition for the cell value is met.

Use refresh() API call after to redraw the component and see changes.

Parameters

Conditional Format Object – the object that describes the conditional formatting rule.

Examples

1) If cell value is more than 400000, then apply trueStyle to this cell:

var condition = {
  id: 1,
  formula: 'if(#value > 400000, "trueStyle")',
  trueStyle: {fontSize : 10, backgroundColor: "#33BB33"},
};
flexmonster.addCondition(condition);
flexmonster.refresh();

Open the example on JSFiddle.

2) This rule will be applied only to Sales measure totals and subtotals cells. If Sales is between 100000000 and 200000000, then apply trueStyle to the cell, else apply falseStyle.

var condition = {
  id: 2,
  measure: "Sales",
  isTotal: true,
  formula: 'if(AND(#value > 100000000, #value < 200000000), "trueStyle", "falseStyle")',
  trueStyle: {fontSize : 11, backgroundColor: "#00FF00"},
  falseStyle: {fontSize : 11, color: "#000000"}
};
flexmonster.addCondition(condition);
flexmonster.refresh();

Check how it works on JSFiddle.

See also

getCondition
getAllConditions
removeCondition
removeAllConditions
refresh