Overview
Version
Report Server Version | Functional Change |
---|---|
11.0 | / |
Problem Description
During report querying, the header and footer information will be displayed even if no query results are returned, as shown in the following figure.
Expected effect: For queries with empty results, nothing is displayed in the report area. For queries with returned results, the report is normally displayed, as shown in the following figure.
Implementation Method
1. You can select the cell where the query result is located. As mentioned in section "Problem Description", the query result is the data of Region displayed in A2.
2. The whole report area will be hidden if the cell is empty.
3. You can hide the report by two schemes.
Scheme one: You can set the row height to 0 in Condition Attribute.
Scheme two: You can add a Loading End event and write a JavaScript script.
Example
Data Preparation
1. Choose File > New General Report on the menu bar to create a general report, as shown in the following figure.
2. Click + on the dataset management panel and create a database query with the SQL statement SELECT * FROM Sales_Volume WHERE Region='${Region}', as shown in the following figure.
Table Design
1. Enter text in cells A1 to C1 and drag the corresponding data columns to cells A2 to C2, as shown in the following figure.
2. Select cell C2, click the Cell Element icon on the right attribute panel, and set Data Setting to Summary, as shown in the following figure.
3. Merge cells A3 and B3, enter the text in the merged cell, and insert the formula SUM(C2) into cell C3, as shown in the following figure.
Parameter Setting
1. Click the editing icon to enter the parameter editing panel, add the parameter Region to the parameter panel, and set the widget type to Text Widget, as shown in the following figure.
Scheme One: Condition Attribute Setting
1. Select cells A1 to B3, click Condition Attribute on the right attribute panel, and click + to add a condition attribute.
2. Click +, select Row Height, and set Row Height to 0. Select Formula as Type, and add the formula condition len(A2)=0. If no data meets the query condition, the table will be hidden, as shown in the following figure.
Scheme Two: Loading End Event Adding
1. Choose Template > Web Attribute, select Pagination Review Setting, and select Set for This Template Separately in Following Settings.
2. Click + in Event Setting, select Loading End, and enter the JavaScript codes. If no data meets the query condition, the table will be hidden, as shown in the following figure.
The JavaScript codes are as follows:
if ($("[id^=A2]").text().length == 0) {
$(".x-table").css("display", "none");
}
Effect Display
PC
Save the report and click Pagination Preview. The two schemes mentioned above have the same effect, as shown in the following figure.
Mobile Terminal
Scheme two: The added Loading End event cannot be previewed on the mobile terminals.
Scheme one: The set condition attribute can be previewed on the mobile terminals, as shown in the following figure.
Template Download
For details, you can download the template of scheme one: Displaying No Report Content Upon Empty Query Result.cpt.
For details, you can download the template of scheme two: Displaying No Report Content Upon Empty Query Result-JS.cpt.