[thelist] sorting vertically into html table columns

.jeff jeff at members.evolt.org
Thu Feb 28 19:09:01 CST 2002


> From: rudy
> > Today, I was asked by a client to display a recordset
> > of unknown amount in an unknown number of columns
> > in a table, sorted vertically in alphabetical order
> hey matt, a while back i wrote some CF code that'll do
> exactly what you describe in three columns -- and
> balanced, too, so that there's "n/3 plus or minus 1"
> entries in each column
> ... and then jeff generalized it to N columns!
> don't reinvent the wheel
> both my code and jeff's version are in the tip
> harvester somewhere, but i'll be durned if i can
> find it -- the tip harvester search doesn't seem
> to like any of the search words i toss at it...
> perhaps jeff will recall...

yup, here's mine:


i think i improved on it though (rummages around in *huge* local collection
of cf crap)

  <cfset currentrow = 1>
  <cfset records = getdocuments.recordcount>
  <cfset columns = app.columns>
  <cfset rows = Ceiling(records / columns)>
  <cfif Ceiling(records / (columns - 1)) EQ rows>
    <cfset columns = columns - 1>
  <cfif columns GT records>
    <cfset columns = records>
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
  <cfloop from="1" to="#rows#" index="row">
  <cfset currentrow = 1>
    <cfloop from="1" to="#columns#" index="column">
      <cfset currentrow = 1>
      <cfset currentrow = (row - 1) + column>
      <cfif column GT 1>
        <cfset currentrow = (rows * (column - 1)) + row>
    <td valign="top"
        width="#Val(100 / columns)#%"
      <cfif (row MOD 2 AND column MOD 2)
         OR (NOT row MOD 2 AND NOT column MOD 2)>
      <cfif column EQ columns AND currentrow GT records>
    <table cellpadding="4" cellspacing="0" border="0" width="100%">
      <td align="right" valign="top">
      <td align="left" valign="top">
      <td align="left"
      ><img src="/documents/#getdocuments.sm[currentrow]#"
            width="100" border="0" class="thumbnail"
            alt="#Replace(getdocuments.name[currentrow], """", "&quot;",
"ALL")# (#getdocuments.id[currentrow]#)" /

produces this (watch wrap):




jeff at members.evolt.org

More information about the thelist mailing list