[thelist] sorting vertically into html table columns

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


rudy,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 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:

http://lists.evolt.org/index.cfm/a/harvest/b/detail/c/_/d/3287

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>
  <cfif columns GT records>
    <cfset columns = records>
  </cfif>
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
  <cfloop from="1" to="#rows#" index="row">
  <cfset currentrow = 1>
  <tr>
    <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>
      </cfif>
    <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)>
        class="alternate"
      </cfif>>
      <cfif column EQ columns AND currentrow GT records>
    &nbsp;
      <cfelse>
    <table cellpadding="4" cellspacing="0" border="0" width="100%">
    <tr>
      <td align="right" valign="top">
      <h5>#currentrow#.</h5>
      </td>
      <td align="left" valign="top">
      <h5>#getdocuments.name[currentrow]#</h5>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="left"
          valign="top"
      ><img src="/documents/#getdocuments.sm[currentrow]#"
            width="100" border="0" class="thumbnail"
            alt="#Replace(getdocuments.name[currentrow], """", "&quot;",
"ALL")# (#getdocuments.id[currentrow]#)" /
      ></td>
    </tr>
    </table>
      </cfif>
    </td>
    </cfloop>
  </tr>
  </cfloop>
  </table>

produces this (watch wrap):

http://documents.pape.com/search/?keywords=studio&option=any&maxrows=10&colu
mns=5&thumbnails=1

enjoy,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list