[cgiapp] Variable Number of Column in a Table

Sean Davis sdavis2 at mail.nih.gov
Thu May 15 12:29:52 EDT 2008


On Thu, May 15, 2008 at 12:21 PM, Joshua Miller <unrtst at gmail.com> wrote:
> Yes, but it's not pretty...

And it may be pretty slow for largish result sets.

You could also consider using client-side javascript to do the table
layout and sending the data as JSON, but that obviously adds a level
of complexity.


>  <TMPL_LOOP NAME=SQL_OUTPUT>
>   <TMPL_IF NAME="__first__">
>     <TR>
>     <TMPL_LOOP NAME=COLS>
>       <TH>Headers go here</TH>
>     </TMPL_LOOP>
>     </TR>
>   </TMPL_IF>
>
>   <TMPL_IF NAME="__odd__">
>     <TR>
>     <TMPL_LOOP NAME=COLS>
>       <TD>Row of data in odd row color set</TD>
>     </TMPL_LOOP>
>     </TR>
>   </TMPL_IF>
>
>   <TMPL_UNLESS NAME="__odd__">
>     <TR>
>     <TMPL_LOOP NAME=COLS>
>       <TD>Row of data in even row color set</TD>
>     </TMPL_LOOP>
>     </TR>
>   </TMPL_UNLESS>
>  </TMPL_LOOP>
>
> $data = {
>    SQL_OUTPUT => [
>        { COLS => [ { CELLDATA => "blah" },
>                    { CELLDATA => "blah" },
>                    { CELLDATA => "blah" },
>                  ] },
>        { COLS => [ { CELLDATA => "blah" },
>                    { CELLDATA => "blah" },
>                    { CELLDATA => "blah" },
>                  ] },
>        ],
>    };
>
> --
> Josh I.
>
> On Thu, May 15, 2008 at 12:03 PM, Stephen Carville <
> stephen.carville at gmail.com> wrote:
>
>> Is there any way to have a template where the number of columns is
>> determined at run time?  I know how to use TMPL_LOOP but that only
>> lets me vary the number of rows.
>>
>> What I'm doing is creating a template for SQL reports so I want a
>> structure like:
>>
>>  <TMPL_LOOP NAME=SQL_OUTPUT>
>>    <TMPL_IF NAME="__first__">
>>      Headers go here
>>    </TMPL_IF>
>>
>>    <TMPL_IF NAME="__odd__">
>>      Row of data in odd row color set
>>    </TMPL_IF>
>>
>>    <TMPL_UNLESS NAME="__odd__">
>>      Row of data in even row color set
>>    </TMPL_UNLESS>
>>  </TMPL_LOOP>
>>
>>
>> --
>> Stephen Carville
>>
>> #####  CGI::Application community mailing list  ################
>> ##                                                            ##
>> ##  To unsubscribe, or change your message delivery options,  ##
>> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
>> ##                                                            ##
>> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
>> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
>> ##                                                            ##
>> ################################################################
>>
>>
>
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################
>
>


More information about the cgiapp mailing list