zen of coding

Excellent HTML table helper

If your application requires to display a lot of data from the DB, then I suggest you take a look at this nice, little HTML table helper: http://cakeforge.org/snippet/detail.php?type=snippet&id=162

Basically it will allow you to pass a data array from the find method and it will construct an HTML table with just a few lines of code.

Be sure to take a look at the source code for a complete usage example.

One issue that I’ve come across is that it’s not easy to setup conditional links. Meaning, to be able to display “Activate” or “Deactivate” depending on your current User status in the DB, for example. I will probably add a modification for this feature in the next few days.

Oh and here’s some CSS that will produce pretty nice looking tables:

[sourcecode language=’css’]
table
{
border-collapse: collapse;
}

th {
font-weight: bold;
font-size: 11px;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-transform: uppercase;
text-decoration: none;
color: #6D929B;
border-left: 1px solid #F5FAFA;
border-top: 1px solid #F5FAFA;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 5px 12px 5px 5px;
background: #CAE8EA;
}

td {
font-size: 11px;
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000;
border: 1px solid #C1DAD7;
background: #fff;
padding: 3px 12px 3px 3px;

}

tr.altRow td {
background: #F5FAFA;
color: #000;
}
[/cc]

  • hmm.. nice.. Maybe one day I merge this helper with the jQuery tablesorter plugin. That would be great.

  • ddg

    tableHeaders(array_keys($updated_pur[0][‘purchaserowmaterials’]));
    foreach ($updated_pur as $thispur)
    {
    echo $html->tableCells($thispur[‘purchaserowmaterials’]);
    }
    ?>

%d bloggers like this: