3.6.3 Displaying Images in Table Cells

A script can load an image file from a URL or as a resource, as long as the file is located on the classpath (i.e., within a classpath directory, or within a JAR file on the classpath). To load the image into a report, use the global getImage() method.

Note: The 'checkon.gif' and 'checkoff.gif' images are packaged in the JAR files inside the webapp lib folder (e.g., sree.jar, bisuite.jar, etc.)

var onIcon =

  getImage('/inetsoft/report/painter/images/checkon.gif');

 

var offIcon =

  getImage('/inetsoft/report/painter/images/checkoff.gif');

Note: A painter/image element has an 'image' property that contains the current image. It can also be assigned an image object from a script.

Once you have loaded an image, you can assign it to a table cell as a regular data object. For example, the script below replaces true and false with the “checkmark” images loaded earlier.

for(var r = 1; r < table.length; r++) {

  if(table[r][1]) {

    table[r][1] = onIcon;

  }

  else {

    table[r][1] = offIcon;

  }

}

You can load an image from an ASCII-encoded string, such as an XML file. (ASCII Hex and ASCII85 are supported.) If the argument to getImage() does not point to a valid resource, then the parameter is treated as an encoded image.

// picture column is ascii85-encoded gif image

for(var r = 1; r < table.length; r++) {

  var img = getImage(table[r]['picture']);

  table[r]['picture'] = img;

}

You can also specify the image to display in a table cell by calling getImage() from within the cell 'Formula' in the Data tab of the Properties panel. For example, select a cell of a table (regular table or formula table), and enter the following text in the Data tab of the Properties panel:

getImage('http://visualizefree.com/images/inetsoft.png')

 

Press 'Apply' and preview the report. The image is displayed in the selected table cell.

 

<< 3.6.2 Setting Cell and Row Visual Properties © 1996-2013 InetSoft Technology Corporation (v11.5) 3.7 Formula Tables >>