Conditional Formatting
Applies to: Kyvos Reporting
You can use scripting in Kyvos Reporting to apply conditional formatting, suppress rows, or perform conditional calculations during report execution. Scripting is written in JavaScript and is typically applied at the Detail section level using events such as OnFormat, OnDataInitialize, and OnFetchData.
Conditional Formatting
You can use script to dynamically highlight or show shapes based on data values. For example, to highlight a field when its value changes compared to the previous row:
Steps:
Add a TextBox (e.g.,
txtBox) in the ReportHeader and set:Visible = FalseText = "-999"(a default value unlikely to occur)
Add a Shape (e.g.,
Shape1) around the field (e.g.,dbField) and configure it as a red ellipse.Use the following script:
Object: Detail
Event: OnFormat
function OnFormat() {
if (
rpt.Sections("ReportHeader").Controls("txtBox").text != "-999" &&
rpt.Fields("dbField").value != rpt.Sections("PageHeader").Controls("txtBox").text
) {
rpt.Sections("Detail").Controls("Shape1").visible = true;
} else {
rpt.Sections("Detail").Controls("Shape1").visible = false;
}
rpt.Sections("PageHeader").Controls("txtBox").text = rpt.Fields("dbField").value;
}
Conditional Suppression of Rows
To hide rows based on a field value (e.g., if Name is null), you can:
Method 1: Without Scripting
Set
Visible = Falsefor the controlSet
Height = 0in the Properties window
Method 2: Using Scripting
Object: Detail
Event: OnFormat
function OnFormat() {
if (rpt.Fields("Name").value == null) {
rpt.Sections("Detail").visible = false;
rpt.Sections("Detail").height = 0;
} else {
rpt.Sections("Detail").visible = true;
rpt.Sections("Detail").height = 285;
}
}
Important
For height changes to take effect, ensure CanGrow is set to False on the Detail section. If set to True, the report engine overrides the scripted height.
Conditional Calculation
You can create custom accumulators to perform conditional summation based on data values. For example, summing values based on Account_type:
Object: Report
Event: OnDataInitialize
function OnDataInitialize() {
rpt.Fields.add("valueA");
rpt.Fields.add("valueB");
rpt.Fields("valueA").value = 0;
rpt.Fields("valueB").value = 0;
}
Object: Report
Event: OnFetchData
function OnFetchData(eof) {
if (rpt.Fields("accType").value == "A") {
rpt.Fields("valueA").value =
parseFloat(rpt.Fields("valueA").value) + rpt.Fields("Amt").value;
} else {
rpt.Fields("valueB").value =
parseFloat(rpt.Fields("valueB").value) + rpt.Fields("Amt").value;
}
rpt.Sections("gfDEPT").Controls("txtACC_A").dataValue = rpt.Fields("valueA").value;
rpt.Sections("gfDEPT").Controls("txtACC_B").dataValue = rpt.Fields("valueB").value;
}
This script:
Adds two custom fields
valueAandvalueB.Aggregates amounts based on account type.
Displays the result in the respective group footer controls (
txtACC_A,txtACC_B).
Hiding Page Header and Footer in Studio Reports
Kyvos Reporting allows designers to conditionally hide the Page Header and Page Footer sections using scripting and control tagging.
Steps to Configure:
Assign Tag to Control
Set the
XmlTagNameproperty of a label or field control to a value (e.g.,Header_TAG) that indicates the need to hide the header/footer.
Access Script Editor
Open the script window in Kyvos Reporting Studio.
Add Page Event
Select the Page Header or Page Footer section.
Use the
pageEventproperty to specify the event string that matches theXmlTagNametag (e.g.,Header_TAG).
Write a Script to Hide the Section
var event = rpt.Sections("PageHeader").pageEvent; if (event.contains("Header_TAG")) { rpt.Sections("PageHeader").visible = false; } else { rpt.Sections("PageHeader").visible = true; }Repeat similarly for
PageFooterif needed.