Quickie – Dynamic select and search size

Generally the select box of the Select and Search prompt is wide enough to display all the information you need. But there are times where you need it to show everything.

Is the first option there Chaun Yang Sport Equipment Company? Org? IBM does have a way to fix this issue, but it involves modifying one of the internals, specifically the \webcontent\prompting\properties.js file. In several of my clients, modifying any internal files is expressly forbidden. So I’ve written a quick and somewhat dirty javascript to handle it.

Drag an HTML item to the left of the prompt:

<div id="selectSearch">

Drag an HTML item to the right of the prompt:

</div>
<script>
  var e=document.getElementById('selectSearch');
  var myselect = e.getElementsByTagName('select')[0];
  if(myselect.childNodes.length>0){myselect.style.width=''}
</script>

This code will find the selectSearch div you wrapped the prompt with, find all of the select tags, and if there are any options the select will expand or shrink to fit.

And finally, as usual (when I remember) the report XML:

<report xmlns="http://developer.cognos.com/schemas/report/8.0/" useStyleVersion="10" expressionLocale="en-us">
				<modelPath>/content/folder[@name='Samples']/folder[@name='Models']/package[@name='GO Data Warehouse (query)']/model[@name='model']</modelPath>
				<drillBehavior modelBasedDrillThru="true"/>
				<layouts>
					<layout>
						<reportPages>
							<page name="Page1">
								<style>
									<defaultStyles>
										<defaultStyle refStyle="pg"/>
									</defaultStyles>
								</style>
								<pageBody>
									<style>
										<defaultStyles>
											<defaultStyle refStyle="pb"/>
										</defaultStyles>
									</style>
									<contents><HTMLItem>
			<dataSource>
				<staticValue>&lt;div id="selectSearch"&gt;</staticValue>
			</dataSource>
		</HTMLItem><selectWithSearch parameter="Parameter1" refQuery="Query1"><useItem refDataItem="Retailer"/></selectWithSearch><HTMLItem>
			<dataSource>
				<staticValue>&lt;/div&gt;
&lt;script&gt;
  var e=document.getElementById('selectSearch');
  var myselect = e.getElementsByTagName('select')[0];
  if(myselect.childNodes.length&gt;0){myselect.style.width=''}
&lt;/script&gt;</staticValue>
			</dataSource>
		</HTMLItem></contents>
								</pageBody>
							</page>
						</reportPages>
					</layout>
				</layouts>
			<XMLAttributes><XMLAttribute name="RS_CreateExtendedDataItems" value="false" output="no"/><XMLAttribute name="listSeparator" value="," output="no"/><XMLAttribute name="RS_modelModificationTime" value="2011-06-09T13:50:33.233Z" output="no"/></XMLAttributes><queries><query name="Query1"><source><model/></source><selection><dataItem name="Retailer" aggregate="none"><expression>[Sales (query)].[Retailers].[Retailer]</expression></dataItem></selection></query></queries></report>

The XML is for Cognos 10, but this code was tested successfully on all the flavors of Cognos 8.4.

Advertisements

13 Responses to Quickie – Dynamic select and search size

  1. charon says:

    Nice… im glad i subscribed. have t try this…Ty 🙂

  2. Ravi says:

    Hi,
    Can plz post the java script for changing the default options in the Prompt.

    Thanks
    Ravi

  3. Ravi says:

    Hi,
    Can you plz post the java script for changing the default options in the Prompt??
    thats very helpful to me.

    Thanks
    Ravi

  4. Laura says:

    I was able to modify my prompt page using this – appreciate it very much!

  5. Elizabeth Alves says:

    I have two search and select prompts on the same page and am trying to size both. The first one is working, but the second isn’t re-sizing. Is there any trick to this? Also, is there a similar script to resize a value prompt list box? Thanks!

    • CognosPaul says:

      Hi Elizabeth,

      All that needs to be done is to increment the ID in the div and the getElementById by 1 for each select and search.

      <report xmlns="http://developer.cognos.com/schemas/report/8.0/" useStyleVersion="10" expressionLocale="en-us">
      				<modelPath>/content/folder[@name='Samples']/folder[@name='Models']/package[@name='GO Data Warehouse (query)']/model[@name='model']</modelPath>
      				<drillBehavior modelBasedDrillThru="true"/>
      				<layouts>
      					<layout>
      						<reportPages>
      							<page name="Page1">
      								<style>
      									<defaultStyles>
      										<defaultStyle refStyle="pg"/>
      									</defaultStyles>
      								</style>
      								<pageBody>
      									<style>
      										<defaultStyles>
      											<defaultStyle refStyle="pb"/>
      										</defaultStyles>
      									</style>
      									<contents><table><style><defaultStyles><defaultStyle refStyle="tb"/></defaultStyles><CSS value="border-collapse:collapse"/></style><tableRows><tableRow><tableCells><tableCell><contents><HTMLItem description="Start">
      			<dataSource>
      				<staticValue>&lt;div id="selectSearch"&gt;</staticValue>
      			</dataSource>
      		</HTMLItem><selectWithSearch parameter="Parameter1" refQuery="Query1"><useItem refDataItem="Retailer"/></selectWithSearch><HTMLItem description="End">
      			<dataSource>
      				<staticValue>&lt;/div&gt;
      &lt;script&gt;
        var e=document.getElementById('selectSearch');
        var myselect = e.getElementsByTagName('select')[0];
        if(myselect.childNodes.length&gt;0){myselect.style.width=''}
      &lt;/script&gt;</staticValue>
      			</dataSource>
      		</HTMLItem></contents></tableCell><tableCell><contents/></tableCell></tableCells></tableRow><tableRow><tableCells><tableCell><contents><HTMLItem description="Start">
      			<dataSource>
      				<staticValue>&lt;div id="selectSearch1"&gt;</staticValue>
      			</dataSource>
      		</HTMLItem><selectWithSearch parameter="Parameter1" refQuery="Query1"><useItem refDataItem="Retailer"/></selectWithSearch><HTMLItem description="End">
      			<dataSource>
      				<staticValue>&lt;/div&gt;
      &lt;script&gt;
        var e=document.getElementById('selectSearch1');
        var myselect = e.getElementsByTagName('select')[0];
        if(myselect.childNodes.length&gt;0){myselect.style.width=''}
      &lt;/script&gt;</staticValue>
      			</dataSource>
      		</HTMLItem></contents></tableCell><tableCell><contents/></tableCell></tableCells></tableRow></tableRows></table></contents>
      								</pageBody>
      							</page>
      						</reportPages>
      					</layout>
      				</layouts>
      			<XMLAttributes><XMLAttribute name="RS_CreateExtendedDataItems" value="false" output="no"/><XMLAttribute name="listSeparator" value="," output="no"/><XMLAttribute name="RS_modelModificationTime" value="2011-06-09T13:50:33.233Z" output="no"/></XMLAttributes><queries><query name="Query1"><source><model/></source><selection><dataItem name="Retailer" aggregate="none"><expression>[Sales (query)].[Retailers].[Retailer]</expression></dataItem></selection></query></queries></report>
      
  6. Ismaeel says:

    Hi,

    Is there a way to set the the width of a value prompt (drop down) to a certain value. Then once you click on the drop down the results shown (parameters) are wider than the initial default width of the prompt.

    Thanks!

  7. Steve says:

    Is there a way to pre-populate the choice box with all values? And have the keyword / search be used just to refine the list?

  8. Hi We need to change default option of Select and Search prompt from Starts with any of these keyword to Contains any of these keywords. Above given code is not working. We are using Cognos 8.4.1. Can you please provide the XML of the sample example. Thank you Very much in advance.

    • I tried the above source code given. But i am getting the error. Error given below.
      The report version “http://developer.cognos.com/schemas/report/8.0/” is not supported.
      Expected report version “http://developer.cognos.com/schemas/report/6.0/”.

  9. Berta says:

    These HTML items for ‘Select and Search’ prompt resizing and change the default option for ‘Contains any of that key words’ do not work for Cognos 11.0.6. Is it any way to get that features for ‘Select and Search’ prompt ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: