Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
more useful options
 
PerlMonks  

CGI table problems

by rashley (Scribe)
on Nov 08, 2006 at 17:24 UTC ( [id://582979]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

rashley has asked for the wisdom of the Perl Monks concerning the following question:

Hi all! My app is complex so I'll try to boil it down to the essentials.

I'm constructing a page full of nested tables using CGI. One of my cells is being given an array reference. This results in multiple cells lining up side by side. How can I get them to stack on top of each other?

Once I do that, how can I limit the cell width, and make the text wrap? I've tried:

 $data .= $cgi->start_table({-width=>200});

But it isn't working.

Thanks!

Replies are listed 'Best First'.
Re: CGI table problems
by BaldPenguin (Friar) on Nov 08, 2006 at 17:30 UTC
    Shouldn't
    $data .= $cgi->start_table({-width => 200, -style => 'white-space:nowr +ap' });
    work?
    Update: this of course only applies to the text wrapping

    Don
    WHITEPAGES.COM | INC
    Everything I've learned in life can be summed up in a small perl script!
      That should work, yes. But for some reason it isn't.
Re: CGI table problems
by rashley (Scribe) on Nov 09, 2006 at 08:52 UTC
    Okay, the text wrap wasn't working because a style-sheet was being applied, so I think I can work with that.

    The big problem is getting them to stack vertically instead of horizontally.

Re: CGI table problems
by cLive ;-) (Prior) on Nov 09, 2006 at 10:26 UTC
    You don't provide code, so how can we be sure? My guess is you're sending an arrayref to a td tag:
    print $q->Tr( $q->td($arrayef) );
    which will, of course, create a row of table cells. If you want them as a column instead you'll need to map them:
    print map { $q->Tr( $q->td($_) ) } @{$arrayref};
      I know, unfortunately I didn't provide code. The structure makes rounding up the pertinent parts difficult, but I'll give it a try.

      Here is where I gather the values and insert the array reference:

      my $noteshandler = $dbh->prepare($notessql); $noteshandler->execute($id, $version); while ( my @note = $noteshandler->fetchrow_arrayref() ) { push ( @noteslist, $note[0]); } $attrHashListRef->[$index]->{VALUE} = \@noteslist;

      Here is where I put my tables together:

      ###begin OUTER Table containing part list and selected part info $data .= $cgi->start_table({}); ###begin row in OUTER table. $data .= $cgi->start_Tr({}); ###Left most cell in OUTER table. Contains PartList. $data .= $cgi->td({-valign=>'top'}, renderPartListView($cgi)); ###begin Right cell in OUTER table. Contains Header and selected ###part info. $data .= $cgi->start_td({-valign=>'top' }); ###begin INNER table containing header and view $data .= $cgi->start_table({}); ###Top ROW on INNER table. Containing header $data .= $cgi->Tr({}, $cgi->td({}, pageHeader($cgi, $lca_dbm, $am))); ###begin bottom ROW on INNER table. Containing selected part $data .= $cgi->start_Tr({-width => 20, -style => 'white-space:wrap +'}); $data .= $cgi->td({-valign=>'top'}, renderPartReadView($cgi, $lca_dbm, $am) ###end bottom ROW on INNER table. Containing selected part $data .= $cgi->end_Tr({}); ###end INNER table containing header and view $data .= $cgi->end_table(); ###end Right cell in OUTER table. $data .= $cgi->end_td({}); ###end row in OUTER table. $data .= $cgi->end_Tr(); ###end OUTER Table containing part list and selected part info $data .= $cgi->end_table(); $logger->info("Exiting renderView"); return $data;

      Like I said, not pretty.

        Template it. That's a mess and will be even worse to maintain.
        Fixing a syntax error (missing ");" in the renderPartReadView line, substituting the embedded sub calls by their string representation, I got a table like

        renderPartListView($cgi)
        pageHeader($cgi, $lca_dbm, $am)
        renderPartReadView($cgi, $lca_dbm, $am)

        I'm still not sure where your problem resides. Assuming for now that renderPartListView returns an arrayref, and rather then seeing something like this:

        part1 part2 part3
        pageHeader($cgi, $lca_dbm, $am)
        renderPartReadView($cgi, $lca_dbm, $am)

        you would more like this:

        part0
        pageHeader($cgi, $lca_dbm, $am)
        renderPartReadView($cgi, $lca_dbm, $am)
        part1
        part2

        ???

        Well, it can be done… but is likely to obscure your programm even further.

        "Easiest" way I see (in the sense that you only make 1 local change) is introducing another table [:-/] for the left part, as in:

        part1
        part2
        part3
        pageHeader($cgi, $lca_dbm, $am)
        renderPartReadView($cgi, $lca_dbm, $am)

        To achieve that, replace the call to renderPartListView with the following:

        $cgi->table( map{ $cgi->Tr($cgi->td($_) ) } @{renderPartListView($cgi)} )
Re: CGI table problems
by ww (Archbishop) on Nov 09, 2006 at 10:57 UTC
    adding an appropriate width:nn(units) and max-width:nn (units) to a css declaration for the relevant cells might be a good approach... despite it's non-perlish-ness.

    But I can't resist objecting to nested tables.

    • They're murder to debug, even when the debugging is in the code, and hellacious to debug in .html
    • They (usually) delay rendering (even tho they no longer bring browswers to their knees, as used to be the case)
    • ymmv: They're in-elegant unless you are using the tables for a structured, multi-tiered dataset rather than solely for layout

    Forgive a disclaimer, please: I'm definitely NOT promoting the notion that "tables (and all other familiar, well-tested, stable html-constructs) are evil; use CSS instead at all expense."

    Update: Fixed grammar & typos in last <li...
    Add remark: This may reflect a failure of imagination on my part, but wanting a vertical stack of <td>s sounds as though it's inspired by layout concerns.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://582979]
Approved by planetscape
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.