问题描述
虽然选择下拉组件中的全选"功能似乎是一个简单的功能,但我很难找到可行的解决方案.我可以找到关于该主题的三个 SO 问题,但没有一种方法完全有效.
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.
如何添加全选选项以在 CDE 中选择组件
Pentaho CDE 重置参数
如何添加一个全选"在 CDE 中选择组件的选项?
我有一个表,其中有一列包含 1-5 的评级(作为字符串类型).我需要让用户选择从 1 到 5 的值或全部".
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".
我创建了一个简单的数据源 (DB2),将数字 1-5 作为字符串拉入.如果在下面适用,我会 UNION ALL
使用 ''
或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))
我按预期使用选择组件"和简单参数"功能.我已经尝试将参数属性值"设置为等于 ''
、All"和数字 1-5,但我只能获得 eitherAll" 或要工作的数字选择.在这种方法的大约 50 次迭代中,我从来没有一次成功地完成两者的工作.
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.
是否有一种简单或直接的方法来添加全部"选择而不切换到多选组件或附加 JavaScript?
Is there a simple or straightforward way to add an "All" selection without switching to a multi-select component or additional JavaScript?
推荐答案
我最终解决了这个问题,(部分感谢@dooms 和@Óscar Gómez Alcañiz 的建议).
I ended up figuring this out, (thanks partially to the advice of both @dooms and @Óscar Gómez Alcañiz).
当我为我的选择器组件提取评级时,我强制所有内容都输入 str
以便我可以包含全部"组件:
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'))
由于某种原因,在全部"上使用 IN
是不够的.该查询仅在我使用 LIKE
时才有效.然而,如上所述,一切终于如我所愿.
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.
这篇关于Pentaho CDE“全部"“选择"中的选项零件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!