Pentaho CDE “All” option in “Select” component

社会主义新天地 提交于 2019-12-08 10:14:09

问题


While a "Select All" feature in a select dropdown component would seem to be a straightforward feature, I've had an incredibly hard time finding a workable solution. I can find three SO questions on the topic, but none of the approaches work entirely.

How to add a select all option to select component in CDE
Pentaho CDE reset parameter
How to add a "select all" option to select component in CDE?

I have a table with a column that contains ratings from 1-5 (as string-type). I need to give users the option to select either a value from 1-5 or an "All".

I created a simple datasource (DB2) pulling in the numbers 1-5 as strings. When applicable below, I would UNION ALL with a '' or an "All"

SELECT ... WHERE (CAST(RATING AS CHAR) = CAST(${parameter} AS CHAR) OR ${parameter} = '')

SELECT ... WHERE (RATING = ${parameter} OR ${parameter} = '')

SELECT ... WHERE (RATING LIKE (CASE WHEN ${parameter} = 'All' THEN '%' ELSE ${parameter} END))

I use the "Select Component" and "Simple Parameter" features as would be expected. I've experimented with setting the "Parameter Property Value" equal to '', "All", and numbers 1-5, but I can only get either the "All" or the numeric selections to work. In probably 50 iterations of this methodology, I've never once successfully had both work.

Is there a simple or straightforward way to add an "All" selection without switching to a multi-select component or additional JavaScript?


回答1:


If I understand correctly you want users to be able to filter certain information on this rating (e.g. a movies list) but when no rating is selected all movies should be shown.

I've come across this multiple times and while this solution might not be the best out there it's very easy to implement and it works.

basically you create an SQL where you select your data for the select-component

SELECT RATING
UNION
SELECT '...'
ORDER BY RATING

Now add a Simple Parameter 'Rating' or whatever you'd like to call it. And use it in your main query (for which the filter is required) like so:

SELECT 'all the data you want to show'
FROM 'your table'
WHERE 'your conditions'
AND
CASE WHEN ${Rating} NOT LIKE '...' THEN RATING = ${Rating} else RATING NOT IN ('dummy value') END 

where the 'dummy value' stands for any value that would never occur inside your RATINGS table.




回答2:


I ended up figuring this out, (thanks partially to the advice of both @dooms and @Óscar Gómez Alcañiz).

When I pulled in the ratings for my selector component, I forced everything to type str so that I could include the 'All' component:

SELECT 'All' AS RATING
FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT '1'
FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT '2'
FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT '3'
FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT '4'
FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT '5'
FROM SYSIBM.SYSDUMMY1

Then in the query for my table component, I added this condition:

WHERE (MY_RATING IN (${Rating_Parameter}) OR ${Rating_Parameter} LIKE ('All'))

For some reason, using IN is not sufficient on the 'All'. The query only worked if I used LIKE. As written above, however, everything finally worked how I desired.



来源:https://stackoverflow.com/questions/38925524/pentaho-cde-all-option-in-select-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!