如何解决Cognos 11 - 搜索和选择提示 - 重置选择、输入关键字和结果
我需要在单击按钮时重置提示,在我的情况下是“RESET”按钮,如下面的屏幕截图所示。我可以在 customControl 中使用 clearValues() JavaScript API 清除 Month-Year 和 Order-Method VALUE 提示,但使用 Search and Select 提示 clearValues() 函数仅清除 SnS 提示中结果窗格中的选定值,但我们需要清除结果窗格中的输入关键字和结果,我可以通过设置输入标签的 .value(用于关键字)并重置包含结果选项的 Div 的 html 来清除它们,但是当页面重新加载之前选择的关键字,结果选择重新出现,例如在您重置然后将年份从 2011 年切换到 2012 年或反之亦然后,之前搜索的输入关键字和结果会重新出现在 SnS 提示中。
[在此处输入图片说明][1]
报告 XML
<report xmlns="http://developer.cognos.com/schemas/report/15.5/" expressionLocale="en-us" useStyleVersion="11.6">
<drillBehavior/>
<layouts>
<layout>
<reportPages>
<page name="Page1">
<style>
<defaultStyles>
<defaultStyle refStyle="pg"/>
</defaultStyles>
</style>
<pageBody>
<style>
<defaultStyles>
<defaultStyle refStyle="pb"/>
</defaultStyles>
</style>
<contents><table><style><CSS value="border-collapse:collapse;width:100%"/><defaultStyles><defaultStyle refStyle="tb"/><defaultStyle refStyle="GuidedLayoutMargin"/></defaultStyles></style><tableRows><tableRow><tableCells><tableCell><contents><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="border-collapse:collapse"/></style><tableRows><tableRow><tableCells><tableCell><contents/><style><CSS value="text-align:left;vertical-align:top"/></style></tableCell><tableCell><contents/><style><CSS value="text-align:left;vertical-align:top"/><defaultStyles><defaultStyle refStyle="GuidedLayoutLeftPadding"/></defaultStyles></style></tableCell></tableCells></tableRow></tableRows></table></contents><style><CSS value="text-align:left;vertical-align:top;width:50%"/><defaultStyles><defaultStyle refStyle="GuidedLayoutRightPadding"/></defaultStyles></style></tableCell><tableCell><contents/><style><CSS value="text-align:left;vertical-align:top;width:50%"/><defaultStyles><defaultStyle refStyle="GuidedLayoutLeftPadding"/></defaultStyles></style></tableCell></tableCells></tableRow></tableRows></table><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="border-collapse:collapse"/></style><tableRows><tableRow><tableCells><tableCell><contents/></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents><textItem><dataSource><staticValue>Select Year</staticValue></dataSource></textItem></contents><style><CSS value="font-weight:bold"/></style></tableCell><tableCell><contents><textItem><dataSource><staticValue>Select Month-Year</staticValue></dataSource></textItem></contents><style><CSS value="font-weight:bold"/></style></tableCell><tableCell><contents><textItem><dataSource><staticValue>Search and Select Product Type</staticValue></dataSource></textItem></contents><style><CSS value="font-weight:bold"/></style></tableCell><tableCell><contents><textItem><dataSource><staticValue>Select Order Method</staticValue></dataSource></textItem></contents><style><CSS value="font-weight:bold"/></style></tableCell><tableCell><contents/></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents><selectValue name="PeriodPmt" parameter="p_period" refQuery="Query2" selectValueUI="radioGroup" autoSubmit="true"><style><CSS value="height:60px"/></style><defaultSelections><defaultSimpleSelection>2011</defaultSimpleSelection></defaultSelections><selectOptions><selectOption useValue="2011"><displayValue>2011</displayValue></selectOption><selectOption useValue="2012"><displayValue>2012</displayValue></selectOption></selectOptions><useItem refDataItem="Year"><displayItem refDataItem="Year"/></useItem></selectValue></contents><style><CSS value="vertical-align:top;padding-left:30px"/></style></tableCell><tableCell><contents><selectValue cascadeOn="p_period" name="MonthPmt" parameter="p_months" refQuery="Query2"><useItem refDataItem="Month key"><displayItem refDataItem="Month (caption)"/></useItem></selectValue></contents><style><CSS value="vertical-align:top;padding-left:30px"/></style></tableCell><tableCell><contents><selectWithSearch hideAdornments="true" name="SNS" parameter="p_product" refQuery="Query1"><useItem refDataItem="Product"><displayItem refDataItem="Product"/></useItem></selectWithSearch></contents><style><CSS value="vertical-align:top;padding-left:30px"/></style></tableCell><tableCell><contents><selectValue name="OrderMethodPmt" parameter="p_orderMethod" refQuery="Query3"><useItem refDataItem="Order method type"><displayItem refDataItem="Order method type"/></useItem></selectValue></contents><style><CSS value="vertical-align:top;padding-left:30px"/></style></tableCell><tableCell><contents><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="border-collapse:collapse;width:100%;border:1pt solid black"/></style><tableRows><tableRow><tableCells><tableCell><contents><promptButton type="finish">
<contents><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="margin:0px;border-collapse:collapse;width:46px;height:22px"/></style><tableRows><tableRow><tableCells><tableCell><contents><textItem><dataSource><staticValue>✓</staticValue></dataSource><style><CSS value="font-family:'Davita Icons';font-size:14px;color:#1566A7;width:15px;height:17px"/></style></textItem></contents><style><CSS value="text-align:left;vertical-align:middle;padding-right:4px"/></style></tableCell><tableCell><contents><textItem><dataSource><staticValue>Apply</staticValue></dataSource></textItem></contents><style><CSS value="text-align:left;height:22px;width:46px;vertical-align:middle;font-family:Lato;font-size:16px"/></style></tableCell></tableCells></tableRow></tableRows></table></contents>
<style>
<CSS value="padding:0px;height:22px;width:46px;color:#1566A7;border-top-style:none;border-bottom-style:none;border-left-style:none;border-right-style:none;background-color:white"/></style>
</promptButton></contents><style><CSS value="padding-right:10px;border:1pt solid black"/></style></tableCell><tableCell><contents><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="margin:0px;border-collapse:collapse;width:46px;height:22px"/></style><tableRows><tableRow><tableCells><tableCell><contents><textItem><dataSource><staticValue>x</staticValue></dataSource><style><CSS value="font-family:'Davita Icons';font-size:14px;color:#1566A7;width:15px;height:17px"/></style></textItem></contents><style><CSS value="text-align:left;vertical-align:middle;padding-right:4px"/></style></tableCell><tableCell><contents><customControl description="CustomReset" name="CustomFinishCancelClear" path="/javascript/poc/clearPrompts.js"><configuration>{
"noSelectPrompts": [
"OrderMethodPmt","MonthPmt"
],"SnSPrompts": [
"SNS"
],"preSelectPrompts": [
{
"promptName": "PeriodPmt","promptDefault": [
{
"use": "2011","display": "2011"
}
]
}
]
}</configuration></customControl></contents><style><CSS value="text-align:left;height:22px;width:46px;vertical-align:middle;font-family:Lato;font-size:16px"/></style></tableCell></tableCells></tableRow></tableRows></table></contents><style><CSS value="padding-right:20px;padding-left:10px"/><defaultStyles><defaultStyle refStyle="GuidedLayoutLeftPadding"/></defaultStyles></style></tableCell></tableCells></tableRow></tableRows></table></contents><style><CSS value="vertical-align:top;padding-left:30px"/><defaultStyles><defaultStyle refStyle="GuidedLayoutTopPadding"/><defaultStyle refStyle="GuidedLayoutBottomPadding"/><defaultStyle refStyle="GuidedLayoutLeftPadding"/></defaultStyles></style></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents/><style><CSS value="vertical-align:top"/></style></tableCell><tableCell><contents/></tableCell><tableCell><contents><customControl description="defaultSnS" path="/javascript/defaultSnS-min.js" uiType="none"><configuration>{
"promptName": "SNS","option": 3,"height": 250
}</configuration></customControl></contents></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents/><style><CSS value="background-color:#99CCFF;height:10px"/></style></tableCell><tableCell><contents/><style><CSS value="background-color:#99CCFF;height:10px"/></style></tableCell><tableCell><contents/><style><CSS value="background-color:#99CCFF;height:10px"/></style></tableCell><tableCell><contents/><style><CSS value="background-color:#99CCFF;height:10px"/></style></tableCell><tableCell><contents/><style><CSS value="background-color:#99CCFF;height:10px"/></style></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents><promptButton type="reprompt" name="RepromptButton">
<contents><textItem><dataSource><staticValue>Display Parameters Selected</staticValue></dataSource></textItem></contents>
<style>
<defaultStyles>
<defaultStyle refStyle="bp"/>
</defaultStyles>
</style>
</promptButton></contents></tableCell><tableCell><contents><textItem><dataSource><staticValue>Product Type Selected</staticValue></dataSource></textItem></contents><style><CSS value="text-align:right"/></style></tableCell><tableCell><contents><textItem><dataSource><reportExpression>ParamDisplayValue('p_product')</reportExpression></dataSource></textItem></contents></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents/></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell><tableCell><contents/></tableCell></tableCells></tableRow></tableRows></table></contents>
</pageBody>
</page>
</reportPages>
</layout>
</layouts>
<queries><query name="Query1">
<source>
<model/>
</source>
<selection><dataItem aggregate="none" rollupAggregate="none" name="Product"><expression>[Sales (query)].[Products].[Product type]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="3"/><XMLAttribute output="no" name="RS_dataUsage" value="0"/></XMLAttributes></dataItem></selection>
</query><query name="Query2"><source><model/></source><selection><dataItem aggregate="none" rollupAggregate="none" name="Year"><expression>[Sales (query)].[Time].[Year]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="1"/><XMLAttribute output="no" name="RS_dataUsage" value="0"/></XMLAttributes></dataItem><dataItem aggregate="none" name="Month"><expression>[Sales (query)].[Time].[Month]</expression></dataItem><dataItem aggregate="none" rollupAggregate="none" name="Month key"><expression>[Sales (query)].[Time].[Month key]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="1"/><XMLAttribute output="no" name="RS_dataUsage" value="1"/></XMLAttributes></dataItem><dataItem aggregate="none" rollupAggregate="none" name="Month (caption)"><expression>[Sales (query)].[Time].[Month (caption)]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="3"/><XMLAttribute output="no" name="RS_dataUsage" value="0"/></XMLAttributes></dataItem><dataItem aggregate="none" rollupAggregate="none" name="Month1"><expression>[Sales (query)].[Time].[Month]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="3"/><XMLAttribute output="no" name="RS_dataUsage" value="0"/></XMLAttributes></dataItem><dataItem aggregate="none" rollupAggregate="none" name="Month number"><expression>[Sales (query)].[Time].[Month number]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="1"/><XMLAttribute output="no" name="RS_dataUsage" value="0"/></XMLAttributes></dataItem></selection><detailFilters><detailFilter><filterExpression>[Year] in ('2011','2012')</filterExpression></detailFilter></detailFilters></query><query name="Query3">
<source>
<model/>
</source>
<selection><dataItem aggregate="none" rollupAggregate="none" name="Order method type"><expression>[Sales (query)].[Order method].[Order method type]</expression><XMLAttributes><XMLAttribute output="no" name="RS_dataType" value="3"/><XMLAttribute output="no" name="RS_dataUsage" value="0"/></XMLAttributes></dataItem></selection>
</query></queries><XMLAttributes><XMLAttribute output="no" name="RS_CreateExtendedDataItems" value="true"/><XMLAttribute output="no" name="listSeparator" value=","/><XMLAttribute output="no" name="decimalSeparator" value="."/><XMLAttribute output="no" name="RS_modelModificationTime" value="2015-11-25T21:38:24.820Z"/></XMLAttributes><classStyles><classStyle name="GuidedLayoutLeftPadding"><CSS value="padding-left:5px;border-top-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-width:1px"/></classStyle><classStyle name="GuidedLayoutTopPadding"><CSS value="padding-top:5px;border-top-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-width:1px"/></classStyle><classStyle name="GuidedLayoutRightPadding"><CSS value="padding-right:5px;border-top-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-width:1px"/></classStyle><classStyle name="GuidedLayoutBottomPadding"><CSS value="padding-bottom:5px;border-top-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-width:1px"/></classStyle><classStyle name="GuidedLayoutMargin"><CSS value="margin-bottom:10px"/></classStyle></classStyles><modelPath>/content/folder[@name='Samples']/folder[@name='Extended']/folder[@name='Models']/package[@name='GO sales (query)']/model[@name='model']</modelPath><reportName>resetPrompts</reportName></report>
JAVASCRIPT 文件:文件名:clearPrompts.js
define(["jquery"],function() {
"use strict";
function validatePromptValue() {}
validatePromptValue.prototype.initialize = function(oControlHost,fnDoneInitializing) {
var o = oControlHost.configuration;
if (!o) {
throw new scriptableReportError("validatePromptValue","","Expected configuration.");
}
this.m_aPromptName = oControlHost.configuration.noSelectPrompts;
this.m_aPromptSnS = oControlHost.configuration.SnSPrompts;
this.m_aPromptDefault = oControlHost.configuration.preSelectPrompts;
console.log(this.m_aPromptDefault);
fnDoneInitializing();
};
validatePromptValue.prototype.draw = function(oControlHost) {
var el = oControlHost.container;
el.innerHTML = "<style>" + '.myButton {border:none; height:22px; width:44px; cursor:pointer; color:#BB0000; font-size:16px; font-family: "Lato"; background-color:white; vertical-align: middle; text-align: left; }' + ".myButton:hover { color:#BB0000; }" + "</style>" + '<button class="myButton btnClear" type="button">Reset</button>';
el.querySelector(".btnClear").onclick = this.f_clearButtonClick.bind(this,oControlHost);
};
validatePromptValue.prototype.f_clearButtonClick = function(oControlHost) {
//No Defaults Prompts
for (let i = 0; i < this.m_aPromptName.length; i++) {
var oControl = oControlHost.page.getControlByName(this.m_aPromptName[i]);
if (oControl) {
if (oControl.name == this.m_aPromptName[i]) {
oControl.clearValues();
}
}
}
//Search and Select Prompts
for (let i = 0; i < this.m_aPromptSnS.length; i++) {
var oControl = oControlHost.page.getControlByName(this.m_aPromptSnS[i]);
if (oControl.name == this.m_aPromptSnS[i]) {
oControl.clearValues();
var srchTxt = oControl.element.getElementsByClassName("clsSelectWithSearchSearchText")[0],resBox = oControl.element.getElementsByClassName('clsAdorment')[0],srchBttn = oControl.element.getElementsByClassName("clsSelectWithSearchSearchButton")[0];
$(srchTxt).attr('value','%');
$(srchTxt).removeAttr('value');
//$(srchTxt).attr('autocomplete','off');
// cognos.Report.Action.REPROMPT;
// $(srchBttn).click();
$(resBox).html('<div class="clsPromptSelectWithSearchMsg" style="line-height:40px; text-align:center;">No Results</div>');
}
}
//Prompts with Default Selectionss
for (let i = 0; i < this.m_aPromptDefault.length; i++) {
var oControl = oControlHost.page.getControlByName(this.m_aPromptDefault[i].promptName);
console.log(oControl);
if (oControl) {
if (this.m_aPromptDefault[i].promptName) {
//oControl.setValues(this.m_aPromptDefault[i].promptDefault);
}
}
}
};
return validatePromptValue;
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。