Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Apr 2016
    Location
    UK
    Posts
    8
    Member #
    53777

    Handling multiple values in a table cell (suppressing blank values)

    I often have tables which are displaying short, structured, data but also need to include some "comments". I normally place these on a second TR row, and COLSPAN the columns to accommodate them.

    The problem arises when I have multiple such comments, I want to display one-per-line, and I want to suppress any that are blank. I can do this in the database query, but its all "quite a lot more FAFF" and I wondered if there was a CSS way that would do this easily?

    CellTextCollapse.jpg

    I have an HTML template like this:
    Code:
    <tr>
    <th>Col1</th><th>Col2</th><th>Col3</th><th>Col4</th></tr>
    <tr>
    <td>Value1</td><td>Value2</td><td>Value3</td><td>Value4</td></tr>
    <tr>
    <td>&nbsp;</td><td colspan=3><b>Header Comment:</b> [HeaderCommentValue]
    <b>Item Comment:</b> [ItemCommentValue]
    </td></tr>
    [HeaderCommentValue] and [ItemCommentValue] tags will be replaced by the actual data from the database.

    I've tried a couple of things, but I'm not sure what is "good HTML" (embeddeing <P> or <DIV> inside <TD> for example) nor of anything else that might work better

    Code:
    <td>&nbsp;</td><td colspan=3><b>Header Comment:</b> [HeaderCommentValue][color red]<br />[/color]
    <b>Item Comment:</b> [ItemCommentValue]
    <td>&nbsp;</td><td colspan=3>[color red]<p>[/color]<b>Header Comment:</b> [HeaderCommentValue][color red]<br />[/color]
    [color red]<p>[/color]<b>Item Comment:</b> [ItemCommentValue]
    The <p> tags give me some additional vertical padding, which I don't really want (but could probably solve with a TD P style in CSS.

    I've tried using
    <TD style="white-space: pre-line")
    which works well, particularly where I just have the [ValueTag] replaced by data (without any "<b>Heading</b>") but I'm stuck on how to suppress the Heading if there is no Value (clearly I can do that in programming, but if there was a way to do it with CSS or similar I could avoid having to faff with programming every time I encounter this issue)

    Given the data:
    HeaderComment ItemComment
    Header1 Item1
    Header2 (blank)
    (blank) Item3
    What I'm currently getting is:
    Header:Header1
    Item:Item1
    Header:Header2
    Item: (blank)
    Header: (Blank)
    Item:Item3

    I'd like to wind up with
    Header:Header1
    Item:Item1
    Header:Header2
    Item:Item3

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Not really, unfortunately. CSS doesn't have anything specific for "null" or "empty" content. Your best bet is to handle this issue on the server side.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    2 ways to go about this. You're going to have to test for a null or empty value. You can either do that on the server side or in the browser. The best option is to do it server side, though you can use JS to check if an element has or lacks a given internal value and set its visibility to hidden.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:30 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com