Set Parameter MultiValue where data are not from database

1 Answer 42 Views
General Discussions Report Designer
Coopbase
Top achievements
Rank 2
Iron
Iron
Coopbase asked on 22 Feb 2024, 08:47 AM | edited on 22 Feb 2024, 08:49 AM
Hello, I would like to ask on how to set the parameter value if it is a MultiValue where the value of that parameter are manually inputted. Basically. there's no database involve. 

I tried to use = Array("Data1", "Data2") to customize the value, now my problem is how to set it as a multivalue  and take the array value separately. The idea is if the multivalue of a aparameter was set into True and then its selection value should have "Data1" and "Data2".

1 Answer, 1 is accepted

Sort by
1
Dimitar
Telerik team
answered on 26 Feb 2024, 04:07 PM

Hello,

Without the usage of some kind of data source component, which as far as I understand you do not wish to use, you would need to create separate report parameters whose values are used in the value of the MultiValue report parameter.

For example, two separately created boolean report parameters can be used to populate the data by using the following expression on the MultiValue parameter:

= Array(
Parameters.Parameter1.Value ? "DataIfParam1True" : "DataIfParam1False",
Parameters.Parameter2.Value ? "DataIfParam2True" : "DataIfParam2False")

With this expression, the array will have two entries with varying data depending on whether the corresponding parameter is true or false. If the array should instead be of a single element when one of the two parameters is false, then the expression may be changed to the following:

= Parameters.Parameter1.Value And Parameters.Parameter2.Value ? Array("Data1", "Data2") : Parameters.Parameter1.Value ? Array("Data1") : Parameters.Parameter2.Value ? Array("Data2") : Null

These examples were created using the ?: operator - the ternary conditional operator - C# | Microsoft Learn but you could also implement them using Telerik Reporting's Conditional Functions at a Glance - Telerik Reporting.

I have attached a sample report to demonstrate the approach. Let me know if you have any questions.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Coopbase
Top achievements
Rank 2
Iron
Iron
commented on 04 Mar 2024, 08:48 AM | edited

Thanks for the idea Dimitar, the suggested solution will work. I have a follow up question.

The checkbox is below the parameter name.
This is what it shows after publishing: 


Is there a way to make the checkbox format like this?




How do I make the checkbox inline with the report parameter name? Since its a bolean, the only value is true or false.
Dimitar
Telerik team
commented on 06 Mar 2024, 02:46 PM

Thank you for the sample screenshots!

Displaying the report parameter text is not supported by default, however, you may insert the text inline with a few lines of JS. For example, you may use the renderingEnd event of the viewer as the point to ensure that the parameter editors are first successfully loaded in the DOM before making your adjustments:

            $("#reportViewer1")
                .telerik_ReportViewer({
                    serviceUrl: "api/reports/",
                    renderingEnd: function(e, args) {
                        var parameterContainers = $("#reportViewer1 .trv-parameter-container");
                        parameterContainers.each(function (index) {
                            var parameterText = $(this).find(".trv-parameter-title").eq(0).text();
                            var parameterValue = $(this).find(".trv-parameter-value").eq(0);

                            $(`<span class="trv-inline-title">${parameterText}</span>`).appendTo(parameterValue);
                        })
                    },
                    reportSource: {
                        report: "Report1.trdp",
                    },

and a few CSS adjustments to hide the header so that the text is not doubled and so that there is some space between the checkbox and the inline title:

        .trv-inline-title {
            margin: 5px;
        }

        .trv-parameter-header {
            display: none;
        }

Please note that the above JS code will be run for all visible report parameters, not only those that are boolean. If you have other types of report parameters, you would need to check what type of parameter the trv.parameter-container element is displaying and skip it if it does not have an element with the class .trv-parameter-editor-boolean in one of its children elements.

Tags
General Discussions Report Designer
Asked by
Coopbase
Top achievements
Rank 2
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or