Created
September 8, 2011 14:49
-
-
Save booyaa/1203586 to your computer and use it in GitHub Desktop.
XPages SSJS code to abbreviate overly long View Column values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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