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

2 Answers 119 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
Accepted
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/.
Leo
Top achievements
Rank 1
commented on 25 Nov 2024, 07:48 AM

Hey Dess,

Thanks a lot! This solutions worked perfectly :)

I encountered a similar situation on another report where the "Data Source" of a table is a report parameter. In this case, the parameter's value is a JSON object.

Now, I’m trying to achieve the same functionality by referencing the parameter's JSON value directly from a panel. Specifically, I want to make the panel invisible if certain values in the JSON are 0. However, I haven’t been able to find a way to accomplish this.

=Parameters.SpecificRecords.Value.key = 0, didnt really work out

Do you have an idea or suggestion on how to achieve this?

Regards,
Leo
Dess | Tech Support Engineer, Principal
Telerik team
commented on 28 Nov 2024, 06:28 AM

Hi, Leo, 

If the SpecificRecords report parameter is setup in such a way that its assigned AvailableValues collection lists all the specific records you want to consider (or other relevant condition applied with the filter rule), you can achieve the desired behavior by simply checking whether the report parameter contains any items that match the filter criteria. Thus, by checking if the report parameter is null (no listed items at all that match the filter condition), you can control the visibility of the panel. However, it is up to the developer to construct the exact filter condition according to the specific requirement.

I hope this would be helpful for making progress in direction you need.

Leo
Top achievements
Rank 1
commented on 04 Dec 2024, 08:13 AM

Hey Dess,

I found out what my "problem" was in my other report that works with jsons.

There is a report parameter that contains a json value that comes from an external source.

This value is then passed on to a jsonDataSource of the report.
(via the DataSource.Source binding of the table that contains the fields)

It seems that my ReportParameter that has the logic to either be null or not to make the panel visible always falls back to the default json values in the reports jsonDataSource.

Im currently checking if I can find a workaround for this issue.


Dimitar
Telerik team
commented on 06 Dec 2024, 01:42 PM

Hi Leo,

Bindings cannot be applied to report parameters so the parameter will always use the default value of the JsonDataSource component that it is connected to.

You would need to change the Source of the JsonDataSource component for the report parameter to use the new data. The good news is that this can be done not only via the Report Designers but through code as well.

You may have a look at the Modify the Report Data Sources through code - Telerik Reporting KB article for details on how to edit the data source components of a report in code.

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.

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