XPage view column - any way to make displayAs property different on each row?

In one column of an XPage view control, I’d like to make some rows display as text, while others display as a link. Is there any way to do this?

I tried computing the basics->displayAs property with script using Math.random(), but it seems the property gets computed once for the whole column before the control is rendered. I’d like to compute it dynamically for each row, based on the row data.

Subject: Thanks Philippe and Martin…

That works well, and I’ve also used a similar solution to produce column icons, since XPage views don’t seem to have an option for that.

Subject: re column icons

On the column properties you can specify an icon property which will be displayed next to the data binding value. Just check the Icon property and provide an image

If that doesn’t give you what you want then, yes, you can compute an icon in the same way I was doing in the previous example, … again, bind to the value prop and set the col to display as html, e.g.

if (rowIndex%2 == 0)

return "<img src = 'Lo.gif'/>";

else

return "<img src = 'tus.gif'/>";

Subject: this approach also works for your first query re “TargetLink”

see my response here

Subject: A simple example …

a) Set the Column content to “Display As HTML”

b) For the “value” property of the column you could write some JavaScript to return either plain text or a link. For instance:

<xp:viewPanel rows=“10” id=“viewPanel1” var=“rowData”

	indexVar="rowIndex">

// …

// …

<xp:viewColumn id=“viewColumn3” contentType=“HTML”>

		<xp:this.facets>

			<xp:viewColumnHeader xp:key="header"

				id="viewColumnHeader3" value="Text And Links">

			</xp:viewColumnHeader>

		</xp:this.facets>

		<xp:this.value><![CDATA[#{javascript:if (rowIndex%2 == 0)

return "plain text";

else

return "<a href='http://www.ibm.com'>html link</a>";}]]></xp:this.value>

	</xp:viewColumn>

This silly snippet returns plain text and links in every other row - but you get the idea

Subject: Dynamic links

It is true that the link property is computed once for the entire view, as this is the normal behavior for a columnTo achive your goal you should can either:

  • Use a repeat control and do your own view layout

  • Display the column as HTML and generate the link by yourself, when necessary