DisplayInColumns ColdFusion custom tag

I wrote a DisplayInColumns custom tag recently for a project and have found it to be extremely useful. The tag minimally accepts as parameters a query and a formatter and optionally includes the number of columns and table attributes. The formatter is a UDF that is called to format each record in the query–referred to as a callback.

With the DisplayInColumns custom tag we can display a record set of names in three columns with the following code (which includes the sample data).

s = "Andrew,Andy,Ba,Bach,Brad,Chafic,Chau,David,Feng,Jay,Jim,Laura" &
"Lucas,Marilyn,Mindy,Nancy,Oanh,Rosa,Sam,Shelly,Thuy,Wang";

q = queryNew("");
queryAddColumn(q, "name", listToArray(s));

This code does three things.

  1. It sets up the source data which for demonstration purposes we’re hard coding.
  2. It creates a myFormatter UDF which formats each record by displaying the record number and the value of the “name” column.
  3. It calls the DisplayInColumns custom tag to display the data in three columns.

The result of this code follows is this table.

s = “Andrew,Andy,Ba,Bach,Brad,Chafic,Chau,David,Feng,Jay,Jim,Laura” &
“Lucas,Marilyn,Mindy,Nancy,Oanh,Rosa,Sam,Shelly,Thuy,Wang”;

q = queryNew(“”);
queryAddColumn(q, “name”, listToArray(s));

The advantage of this custom tag is that by using a callback UDF it is extremely flexible in presentation. The tag also supports providing attributes for the table elements it creates.

You can view or download the tag.

4 thoughts on “DisplayInColumns ColdFusion custom tag

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>