Report Desginer - Hide a Panel in Telerik Report Designer Based on Table Data

2 Answers 23 Views
Conditional Formatting DataSources Report Designer (standalone) Report Parameters Styling Table
Leo
Top achievements
Rank 1
Leo asked on 21 Oct 2024, 09:04 AM

Hi everyone,

I'm working with Telerik Report Designer, and I have a table inside a panel. The panel represents the entire page that gets printed. The table is bound to a JSON data source.

In my JSON data, I have several objects, and some of them have a value of 0.0 If two specific objects have a value of 0.0 I want to hide the panel (and therefore the entire page) to avoid printing out a table with no meaningful values.

The data source is linked to the table, not to the panel, so I am not sure how to make this condition work. I need to hide the panel based on the values within the data.

Does anyone have any idea how I can set up conditional formatting or report parameters to achieve this?

Thanks in advance!


2 Answers, 1 is accepted

Sort by
1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Oct 2024, 08:09 AM

Hello, Leo,

If you want to control the visibility of a report item based on the data, the perfect fit is to use the conditional formatting functionality: Conditional Formatting Overview. Follow the steps:

1. Create a report parameter (boolean type) which value is bound to the specific data source value. It may be necessary to apply an appropriate expression according to the specific requirement you have. Here is the report parameter:

2. Then, using the report parameter's value, set up a conditional formatting rule such that when the value of a Report Parameter <> true, it applies a format where visibility is disabled. In other words: if the ReportParameter value is not equal to true, make the report item invisible.

The Conditional Formatting Rules dialog lets you define rules, that when fired, change the style formatting of the selected item.

The above example can be extended further in a way to apply a more complex expression instead of the value of the report parameter: Using Expressions in Conditional Formatting

Another option to consider is using a report parameter with AvailableValues bound to the exact data values from the source which control the visibility. 

I hope you find this information helpful. Please, let me know if there is anything else I can assist you with.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Leo
Top achievements
Rank 1
commented on 28 Oct 2024, 03:46 PM

Hey @Des, thanks for the reply! I was able to replicate your sample.

But now I want to connect my json data source to a report parameter, and set this parameter to true or false based on if a json value is 0.0.

In  this example I used float, not boolean but the question stays the same - how can I access the datasource in the parameter to change the value.
If I can change the value or access the value I can also use it to make a page visible or invisible according to your example.

Thanks for your help.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 31 Oct 2024, 02:02 PM

Hi, Leo,

If I understand you correctly, you need to show/hide the table with the JSON data based on specific records in the collection. I have further extended my sample report to simulate as close as possible the desired scenario.

Let's consider we have a collection of books and we want to hide the table if two specific books ("Nostromo", "Stories") are published in 1904 for example. Here is my JSON:

[
   {
    "author": "Miguel de Cervantes",
    "country": "Spain",
    "imageLink": "images/don-quijote-de-la-mancha.jpg",
    "language": "Spanish",
    "link": "https://en.wikipedia.org/wiki/Don_Quixote\n",
    "pages": 1056,
    "title": "Don Quijote De La Mancha",
    "year": 1610
  },
  {
    "author": "Geoffrey Chaucer",
    "country": "England",
    "imageLink": "images/the-canterbury-tales.jpg",
    "language": "English",
    "link": "https://en.wikipedia.org/wiki/The_Canterbury_Tales\n",
    "pages": 544,
    "title": "The Canterbury Tales",
    "year": 1450
  },
  {
    "author": "Anton Chekhov",
    "country": "Russia",
    "imageLink": "images/stories-of-anton-chekhov.jpg",
    "language": "Russian",
    "link": "https://en.wikipedia.org/wiki/List_of_short_stories_by_Anton_Chekhov\n",
    "pages": 194,
    "title": "Stories",
    "year": 1886
  },
  {
    "author": "Joseph Conrad",
    "country": "United Kingdom",
    "imageLink": "images/nostromo.jpg",
    "language": "English",
    "link": "https://en.wikipedia.org/wiki/Nostromo\n",
    "pages": 320,
    "title": "Nostromo",
    "year": 1904
  },
  {
    "author": "Charles Dickens",
    "country": "United Kingdom",
    "imageLink": "images/great-expectations.jpg",
    "language": "English",
    "link": "https://en.wikipedia.org/wiki/Great_Expectations\n",
    "pages": 194,
    "title": "Great Expectations",
    "year": 1861
  }
]

Add a report parameter "SpecificRecords" which is populated with the same JSON collection. However, we will filter the collection with the specific records. These specific records should be known and they are books "Nostromo", "Stories" in our example. The second condition in the filter rule is the year is equal to 1904.

It is important that the parameter allows null values.

The next step is to add a conditional formatting rule based on the report parameter with specific values and check if there are any values to hide the table:

I have attached the extended .trdp report. When you preview it in the designer, the SpecificRecords parameter is expected to be marked as NULL and table3 should be hidden:

If we modify the values in the JSON data source and change the year for the specific books as follows:

Then, one book will be shown in the report filter and the condition for hiding the table wouldn't be matched. The table will be displayed:

Note that this report parameter shouldn't be visible as it depends on the data records and the end user is not expected to manipulate it.

Please give the sample report a try. Feel free to further modify and extend it according to your needs.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Tags
Conditional Formatting DataSources Report Designer (standalone) Report Parameters Styling Table
Asked by
Leo
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or