Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 29, 2012 @ 22:07
    bob baty-barr
    0

    question about table row attributes

    so, i am getting a little up the road on making some helpers for rendering tables... however, here is my issue...

    i am rendering a cell that sould span multiple columns i can specify the 

    fo:table-cell number-rows-spanned=""

    but what i want to know is how would i parse the attribute for colspan="" on the actual html table?

    any thoughts?

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jun 30, 2012 @ 13:38
    Darren Ferguson
    0

    Hi Bob,

    Are you writing XSLT or Razor? are you parsing HTML tables from a rich text editor and trying to turn them into fo tables?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 24, 2012 @ 20:43
    bob baty-barr
    0

    Darren, i am using the razor syntax... basically, i need to be able to assign row span based on the <th colspan="4"> attribute - i have a collection of cases... but i am getting somewhat confused.

    here is a sample of the markup from the rich text editor...

    <table border="0" cellspacing="0" cellpadding="0">
    <thead>
    <tr>
    <th colspan="4">How Much You Pay for a Covered Prescription Drug in
    2012</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>&nbsp;</th>
    <th class="ctr" colspan="2">Retail Pharmacy<br />
     (up to a 30-day supply)</th>
    <th class="ctr">Medco By Mail<br />
     (up to a 100-day supply)</th>
    </tr>
    <tr>
    <th>&nbsp;</th>
    <th>First Three Fills</th>
    <th>Each Subsequent Refill</th>
    <th>&nbsp;</th>
    </tr>
    <tr>
    <td>Generic</td>
    <td>20% ($5 minimum)</td>
    <td>35% ($5 minimum)</td>
    <td>20% ($10 minimum)</td>
    </tr>
    <tr>
    <td>Formulary</td>
    <td>20% ($15 minimum)</td>
    <td>35% ($15 minimum)</td>
    <td>20% ($30 minimum)</td>
    </tr>
    <tr>
    <td>Non-formulary</td>
    <td>20% ($30 minimum)</td>
    <td>35% ($30 minimum)</td>
    <td>20% ($60 minimum)</td>
    </tr>
    </tbody>
    </table>

    and here are my case statements...

    case "table":
       <fo:table width="100%" border="1px solid #DAE1E5" margin-bottom="12pt" border-spacing="0" color="#656f74" >
         @ParseRichText(node.ChildNodes)
       </fo:table>
       break;
     
       case "tbody":
       <fo:table-body font-size="10pt">
         @ParseRichText(node.ChildNodes)
       </fo:table-body>
       break;
       case "thead":
    <fo:table-header number-rows-spanned="4" border-bottom="1px solid #26363E" background="#FF0000" padding="3pt" font-weight="bold" text-align="center">
    <fo:table-row>@ParseRichText(node.ChildNodes)</fo:table-row>
    </fo:table-header>
    break;
         
       case "tr":
       <fo:table-row>
         @ParseRichText(node.ChildNodes)
       </fo:table-row>
       break;
       case "th":
      
       <fo:table-cell number-rows-spanned="" border-bottom="1px solid #26363E" background="#DAE1E5" padding="3pt" font-weight="bold" text-align="center">
         <fo:block>@ParseRichText(node.ChildNodes)</fo:block>
       </fo:table-cell>
       break;
       case "td":
       <fo:table-cell border="1px solid #DAE1E5" padding="3pt">
         <fo:block>@ParseRichText(node.ChildNodes)</fo:block>
       </fo:table-cell>
       break;

     

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jul 25, 2012 @ 09:47
    Darren Ferguson
    0

    I don't really understand what you are trying to do based on the description above - but if the 4 in <th colspan="4"> is variable and you want to do some output based on the value then you'd need to modify the ParseRichText function to take a second parameter e.g. ParseRichText(node.ChildNodes, 4)

     

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 09, 2012 @ 16:07
    bob baty-barr
    0

    to expand on the above...

    the client is creating tables in the rich text editor - they are able to have cells span multiple rows, etc. [see markup above as a generic example]

    The challenge comes in when parsing to PDF using the razor examples you have provided. I was able to add case statement to handle the table nodes, etc. but have no idea how to handle a rowspan element on the node to translate that into some xsl:fo syntax to make it work for any tables rendered by the engine.

    does that help? I am actually struggling with this aspect on TWO sites right now and imagine it will continue to come up... so the ability to have a solution for table rendering would be great.

    thanks,

    bob

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 10, 2012 @ 09:59
    Darren Ferguson
    1

    Hi Bob,

    you can access the attributes of the original table like this:

     

    case th:

    @{ var rowSpan = node.Attributes["rowspan"].Value }

    <fo:table-cell number-rows-spanned="@rowSpan"

    break:

     

    Does that help?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 14:57
    bob baty-barr
    0

    i get a generic error when adding that to the th case

     

    case "th":
       @{ var rowSpan = node.Attributes["rowspan"].Value }
       <fo:table-cell number-rows-spanned="@rowSpan" border-bottom="1px solid #26363E" background="#DAE1E5" padding="3pt" font-weight="bold" text-align="center">
         <fo:block>@ParseRichText(node.ChildNodes)</fo:block>
       </fo:table-cell>
       break;

    what am i missing?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 15:13
    bob baty-barr
    0

    here is what the trace shows...

    Error loading MacroEngine script (file: , Type: ''
    d:\HostingSpaces\SegalDev\psccunywf.org\wwwroot\App_Data\TEMP\Razor\inline-09096d6234f6338607892e620d0ef855.cshtml(171): error CS0839: Argument missing
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)


  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 10, 2012 @ 15:19
    Darren Ferguson
    0

    Does a th always have a rowspan? can you look at the temp file mentioned in the error and post line 171?

    d:\HostingSpaces\SegalDev\psccunywf.org\wwwroot\App_Data\TEMP\Razor\inline-09096d6234f6338607892e620d0ef855.cshtml

    If there isn't a rowspan you'd need to do a null check.

     

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 15:20
    bob baty-barr
    0

    ah, there is not ALWAYS a rowspan... so let me try a null check

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 15:45
    bob baty-barr
    0

    grrrr... i hate that i don't know razor :(

    how do i write this null statement?

    @{var rowSpan = string.IsNullOrEmpty(node.Attributes["rowspan"].Value);}

    that is not working???

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 10, 2012 @ 15:53
    Darren Ferguson
    1

    Untested 'cos i don't have Umbraco installed on this PC but something like:

     

    @{var rowSpan = (node.Attributes["rowspan"] == null ? node.Attributes["rowspan"].Value : 1);}
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 10, 2012 @ 15:59
    Ismail Mayat
    1

    bob,

    try node.Attributes["rowspan"]!=null as I suspect you wont have it at all and therefore it cannot test value.

    Regards

    Ismail

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 16:02
    bob baty-barr
    0

    still get the same error - and the error is on this line...

    @{var rowSpan = (node.Attributes["rowspan"] != null ? node.Attributes["rowspan"].Value : 1);}

    any more thoughts?

  • Sean Dooley 289 posts 528 karma points
    Aug 10, 2012 @ 16:51
    Sean Dooley
    0

    Bit of a shot in the dark, is it possible to use node.HasAttribute("rowspan")?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 17:24
    bob baty-barr
    0

    okay, the issue is something completely different...

    this statement even throws an error... why?

     

    @{var rowSpan = 7}

    still says an argument is missing?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 17:37
    bob baty-barr
    0

    okay, i did not need braces... i am getting closer... no i am getting this error

    Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'char'
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

    from this  line

    var rowSpan = (node.Attributes["colspan"].Value != null ? node.Attributes["colspan"].Value : '2');

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Aug 10, 2012 @ 17:38
    Jason Prothero
    1

    Change the '2' to "2" perhaps?

     

    J

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 10, 2012 @ 17:51
    bob baty-barr
    0

    Thanks so much Jason!

    what a great community effort on this one... i am slowly learnign more and more each day... and this thread was a huge help!

     

    thanks to all... so... to close the loop, here is what it all looked like in the end...

    case "th":
       var rowSpan = node.Attributes["colspan"] != null ? node.Attributes["colspan"].Value : "1";
       
       <fo:table-cell number-columns-spanned="@rowSpan" border-bottom="1px solid #26363E" background="#DAE1E5" padding="3pt" font-weight="bold" text-align="center">
         <fo:block>@ParseRichText(node.ChildNodes)</fo:block>
       </fo:table-cell>
       
       break;

    so basically, we are checking for a colspan in the RTE table, if it exists, use the value, if not... set it to 1 - what a cool little app this is ;)

Please Sign in or register to post replies

Write your reply to:

Draft