Menu

Alternating color table rows

Help
Brecht27
2014-12-29
2014-12-31
  • Brecht27

    Brecht27 - 2014-12-29

    Is there any way to use alternating color rows. I have tried to work with an external css file but it's not working. I used: tr:nth-child(even) {background: #CCC} and tr:nth-child(odd) {background: #FFF}

     
  • cpw

    cpw - 2014-12-31

    If everything else fails you can do it "manually":

    require('/tcpdf/tcpdf.php');
    
    $pdf = new TCPDF($orientation = "P", $unit = "mm", $format = "A4", $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false);
    
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    
    $pdf->SetDisplayMode(100, "OneColumn");
    
    $pdf->SetMargins($left = 23.0, $top = 11.0, $right = 17.0, false);
    
    $pdf->AddPage("P", "A4");
    
    $data = array(1,2,3,4,5);
    
    $theHtml = '<table cellspacing="0" cellpadding="0">';
    
    for($i=0; $i<sizeof($data); $i++)
    {
        $theHtml .= '<tr';
    
        if($i % 2 == 0)
        {
            $theHtml .= ' style="background-color:green;"';
        }
    
        $theHtml .= '>
                    <td>
                        '.$data[$i].'
                    </td>
    
                    <td>
                        Something else for '.$data[$i].'
                    </td>
                 </tr>';
    }
    
    $theHtml .= '</table>';
    
    $pdf->writeHTMLCell($w=0, $h=0, $x=0, $y=0, $html=$theHtml);
    
    $pdf->Output(); 
    
     

    Last edit: cpw 2014-12-31

Log in to post a comment.