htmlarraytable
ARRAY
,
ROWSEP
,
COLSEP
,
RESULT
,
OPTIONS

The htmlarraytable statement generates an HTML table from an arrray.


Parameters

This statement has five parameters:

array – Array to be converted

rowsep – Row separator character (default is carriage return)

colsep – Column separator character (default is tab)

result – Name of the field or variable that will contain the final table in HTML format.

options – Option tags (described in detail below).


Description

This statement generates an HTML table from a text array. (If you want to generate an HTML table from a database, see the HTMLDataTable statement. For the examples in this section we will be using the text array shown below. The demoArray variable contains a two dimensional array, with carriage returns as the primary separator character (between rows) and the ~ symbol as the secondary separator (between columns).

local demoArray
demoArray={1~Southern Pacific Box Car~12.99~12.99
1~Western Pacific 2-8-0 Steam Locomotive~189.99~189.99
1~Amtrak Genesis Diesel Locomotive~129.95~129.95
1~Illinois Central Gondoloa~14.99~14.99
1~Santa Fe Box Car (Grand Canyon)~18.99~18.99
1~Union Oil 3 Dome Tank Car~24.99~24.99}

Here is a simple procedure that renders this array into HTML.

htmlarraytable demoArray,cr(),"~",cgiHTML

In the browser the rendered page will look like this:

1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

This table isn’t very attractive but you can easily customize the appearance (see below).

Table Options

To customize the appearance of the table you’ll need to specify some options in the fifth parameter of the htmldatatable statement. The options are specified as assignments, similar to the options in many HTML tags. Here is a basic example (remember that { and } can be used as quote characters).

htmlarraytable demoArray,cr(),"~",cgiHTML,{border=0 font="Verdana" fontsize=-1}

The available option tags are described in the following sections.

Table Column Layout

There are four options that allow you to specify what array columns will be included in the table and how they are titled and arranged. The examples below demonstrate the syntax of these options.

Here’s a very simple example that displays only the first two columns from the array. The last two are ignored.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  column={«1»}
  column={«2»}
|||

Here’s the table rendered by this procedure.

1Southern Pacific Box Car
1Western Pacific 2-8-0 Steam Locomotive
1Amtrak Genesis Diesel Locomotive
1Illinois Central Gondoloa
1Santa Fe Box Car (Grand Canyon)
1Union Oil 3 Dome Tank Car

The next example displays all four columns: Qty, Item, Price and Total. (Note: In this example the options are shown formatted on separate lines for clarity, but this formatting is not necessary.)

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  column={«1»} title={Qty} align=center width=30
  column={«2»} title={Item} align=left width=300
  column={«3»} title={Price} align=right width=60
  column={«4»} title={Total} align=right width=60
|||

This table includes titles, alignment and specific widths.

QtyItemPriceTotal
1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

The columns don’t have to be displayed in the same order that they occur in the array, you can reorder them as necessary.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  column={«1»} title={Qty} align=center width=30
  column={«3»} title={Price} align=right width=60
  column={«2»} title={Item} align=left width=300
  column={«4»} title={Total} align=right width=60
|||

In this example the Price has been moved to the second column of the rendered table, even though it is in the third column of the array.

QtyPriceItemTotal
112.99Southern Pacific Box Car12.99
1189.99Western Pacific 2-8-0 Steam Locomotive189.99
1129.95Amtrak Genesis Diesel Locomotive129.95
114.99Illinois Central Gondoloa14.99
118.99Santa Fe Box Car (Grand Canyon)18.99
124.99Union Oil 3 Dome Tank Car24.99

You can modify the array data with a formula before it is rendered.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  column={«1»} title={Qty} align=center width=30
  column={upper(«2»)} title={Item} align=left width=370
  column={«3»} title={Price} align=right width=60
  column={«4»} title={Total} align=right width=60
|||

This formula displays the second column in all upper case (we’ve also moved the Price column back to the traditional location.

QtyItemPriceTotal
1SOUTHERN PACIFIC BOX CAR12.9912.99
1WESTERN PACIFIC 2-8-0 STEAM LOCOMOTIVE189.99189.99
1AMTRAK GENESIS DIESEL LOCOMOTIVE129.95129.95
1ILLINOIS CENTRAL GONDOLOA14.9914.99
1SANTA FE BOX CAR (GRAND CANYON)18.9918.99
1UNION OIL 3 DOME TANK CAR24.9924.99

You can add text constants to the formula, for example HTML tags. Be careful about quoting, though. In this example you would not want to use or { } as quote characters within the formula.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  column={«1»} title={Qty} align=center width=30
  column={«2»} title={Item} align=left width=300
  column={«3»} title={Price} align=right width=60
  column={"<b>"+«4»+"</b>"} title={Total} align=right width=60
|||

This formula makes the Total column bold.

QtyItemPriceTotal
1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

Remember that numeric values within the array are really text. So if you want to do a calculation with a number (or display it using an output pattern) you must convert it to a number first with the val( function.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  column={«1»} title={Qty} align=center width=30
  column={«2»} title={Item} align=left width=300
  column={«3»} title={Price} align=right width=60
  column={"<b>"+pattern(val(«4»),"$ #,.####")+"</b>"} title={Total} align=right width=90
|||

This example uses the pattern( function to format the totals.

QtyItemPriceTotal
1Southern Pacific Box Car12.99$ 12.9900
1Western Pacific 2-8-0 Steam Locomotive189.99$ 189.9900
1Amtrak Genesis Diesel Locomotive129.95$ 129.9500
1Illinois Central Gondoloa14.99$ 14.9900
1Santa Fe Box Car (Grand Canyon)18.99$ 18.9900
1Union Oil 3 Dome Tank Car24.99$ 24.9900

You can use any operator or function you want in a formula, and you can also include other fields or variables.

Table Font, Font Size and Color

There are four “template” options that allow you to specify how text will be displayed within the table.

Table Borders and Spacing

These options allow you to specify borders and spacing within the table.

Table Background Colors

The color option allows you to specify a background color for the table.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  color="FFFFCC"
  font="Helvetica" size=-1 border=0
  ...

In this example the background color has been set to pale yellow.

QtyItemPriceTotal
1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

If you include two, three or more colors these colors will alternate as each row is rendered.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  color="EEFFFF"
  color="CCFFDD"
  font="Helvetica" size=-1 border=0
  ...

In this example the rows alternate between light blue and green.

QtyItemPriceTotal
1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

The colorpattern option customizes the pattern used to alternate between colors. For example the option colorpattern="1112" will render three rows in the first color, then one row in the second color.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  color="EEFFFF"
  color="CCFFDD"
  colorpattern="111222"
  font="Helvetica" size=-1 border=0
  ...

This pattern produces three rows with a light blue background then three with a green background

QtyItemPriceTotal
1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

The titlecolor option allows you to specify a separate background color for the title row, while the titlefontcolor option specifies the color of the title text.

htmldatatable cgiHTML,|||
  titlecolor="000099"
  titlefontcolor="FFFFFF"
  color="EEFFFF"
  color="CCFFDD"
  colorpattern="111222"
  column="Hotel"
    title="Hotel"
    ...

This example displays the title with white text on a blue background.

QtyItemPriceTotal
1Southern Pacific Box Car12.9912.99
1Western Pacific 2-8-0 Steam Locomotive189.99189.99
1Amtrak Genesis Diesel Locomotive129.95129.95
1Illinois Central Gondoloa14.9914.99
1Santa Fe Box Car (Grand Canyon)18.9918.99
1Union Oil 3 Dome Tank Car24.9924.99

Displaying an Empty Array

If the array is empty the server will display an empty table, like this:

QtyItemPriceTotal

The message displayed in the empty table can be customized with the emptytablemessage option. You can include any text you like in this option, including HTML tags.

htmlarraytable demoArray,cr(),"~",cgiHTML,|||
  emptytablemessage={<center><p>Sorry, no data available<p></center>}
  ...

Now the empty table will include the specified message.

QtyItemPriceTotal

Sorry, no data available

You could even include a link to a new search form as part of the message.

Table HTML Layout

The font, border, spacing and background color options give you almost complete control over the appearance of the table. If you need even more control there are four “template” options that allow you to specify HTML templates for each component of the table.

Consult an HTML book or web site for more information about the <table>, <tr>, <td> and <th> tags.


See Also


History

VersionStatusNotes
10.0No ChangeCarried over from Panorama 6.0.