Skip to content

Instantly share code, notes, and snippets.

@booyaa
Created September 8, 2011 14:49
Show Gist options
  • Save booyaa/1203586 to your computer and use it in GitHub Desktop.
Save booyaa/1203586 to your computer and use it in GitHub Desktop.
XPages SSJS code to abbreviate overly long View Column values
// Handy XPages SSJS to help keep columns fixed width by truncating the content, but keeps the full
// text value as a tool tip using the ABBR tag.
// Still learning my way around XPages SSJS so any feedback is welcome
// Usage: 1) create a view variable callde "rowData" (All Props > Data > var)
// 2) set view column props to display as HTML
// 3) add code to data computed value: renderViewColumnDataAsTruncated("ProductDescription",15)
function renderViewColumnDataAsTruncated(columnName, maxLength)
{
//FIXME: there must be a better way of handling viewScope variables...
if (typeof rowData == "undefined") {
throw "rowData view variable not set";
}
if (!rowData.isDocument()) {
return "";
}
var columnValue = rowData.getColumnValue(columnName);
if (typeof columnValue == "java.util.Vector") { // multivalue column
columnValue = columnValue.toArray().join(",");
}
var abbrStart = "<abbr title=\"" + columnValue + "\">";
var abbrMiddle = columnValue.length > maxLength ? columnValue.substring(0,maxLength) + "..." : columnValue;
var abbrEnd = "</abbr>";
return abbrStart + abbrMiddle + abbrEnd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment