I have a table that looks something like this:
ID | photo | ident | status
------------------------------------------------
80 | img/photo1 | ACH3882 | V
81 | img/photo2 | SHD8837 | V
82 | img/photo3 | SFF4837 | X
83 | img/photo4 | DLL3266 | V
Is it possible to change the rows background color, depending on the value? So if status cell value is V, make yellow, and if X make green?
This is my table, and what I have tried:
<table class="blueTable" border="2" style= "background-color: #f9f9f9; color: #000000; margin: 0 auto;" >
<thead style= "background-color: #FFFFFF">
<tr>
<th>Photo</th>
<th>Ident</th>
<th>Status</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
if ($result = $link->query($query)) {
$num_rows = 0;
while ($row = $result->fetch_assoc()) {
$num_rows++;
if($row['status'] == 'V') {
$style = 'style="background-color:#00FF00;';
}
if($row['status'] == 'X') {
$style = 'style="background-color:#FF00FF;';
}
echo
"<tr>
<td>{$row['photo']}</td>
<td>{$row['ident']}</td>
<td>{$row['status']}</td>
<td><a href='delete.php?id={$row['id']};'>Delete</a></td>
</tr>";
}
/*freeresultset*/
$result->free();
}
?>
</tbody>
</table>
But somehow the background color does not change. Any suggestions?
You can use your status var as a class and add the colors for the classes in css like this
.color-v {
background-color: blue;
}
.color-x {
background-color: green;
}
<table class="blueTable" border="2" style= "background-color: #f9f9f9; color: #000000; margin: 0 auto;" >
<thead style= "background-color: #FFFFFF">
<tr>
<th>Photo</th>
<th>Ident</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
if ($result = $link->query($query)) {
$num_rows = 0;
while ($row = $result->fetch_assoc()) {
$num_rows++;
echo
"<tr class='color-{$row['status']}'>
<td>{$row['photo']}</td>
<td>{$row['ident']}</td>
<td>{$row['status']}</td>
</tr>";
}
/*freeresultset*/
$result->free();
}
?>
</tbody>
</table>
Related
I need to generate a PDF using mPDF and YuGothM.ttc font for a Japanese client. The page I need to export in PDF contains some text which in browser version (HTML) is rendered well, but in the PDF, the same text has some characters using a font and other characters some default font which is not approved by the client. I understand I have to define TTCfontID parameter in every font definition for .ttc files, but I just don't understand the meanings of those definitions and so how to properly configure fonts.
The script is used in a WordPress website using Polylang plugin for translations.
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$pdf = new \Mpdf\Mpdf([
//'mode' => '+aCJK',
'mode' => 'utf-8',
'format' => 'A3-L',
'margin_left' => 5,
'margin_right' => 5,
'margin_top' => 5,
'margin_bottom' => 5,
'fontDir' => array_merge($fontDirs, [
ASSETS_DIR ."fonts/Yugothib/",
]),
'fontdata' => $fontData + [
'yugoth' => [
'R' => 'YuGothR.ttc',
'TTCfontID' => [
'R' => 1,
]
],
],
'default_font' => 'yugoth',
'languageToFont' => new CustomLanguageToFontImplementation()
]);
$pdf->autoScriptToLang = true;
$pdf->autoLangToFont = true;
$pdf->showImageErrors = true;
$pdf->allow_charset_conversion = true;
$pdf->SetHTMLHeader();
$pdf->SetHTMLFooter();
$pdf->WriteHTML($this->getHtmlTemplate($stock, $userId, $loadedDate));
$pdf->Output($filepath, 'F');
And the HTML is also taken from a private function within the same class
function getHtmlTemplate($records, $userId, $loadedDate){
$user = $this->getUserInfo($userId);
$companyName = $user->client;
$html = "
<html lang=\"ja\">
<head>
<style>
.table {
font-family: 'yugoth', sans-serif;
font-size: 16px;
font-weight: normal;
}
.column-header {
text-align: center;
vertical-align: middle;
background-color: #777777;
color: #FFFFFF;
}
.cell{
border-left: 1px solid #efefef;
border-bottom: 1px solid #efefef;
}
.cell-last {
border-right: 1px solid #efefef;
}
.a-center {
text-align: center;
}
.w-80 {
width: 80px;
}
.w-quality {
width: 380px;
}
.w-150 {
width: 150px;
}
</style>
</head>
<body lang=\"ja\">
<table border=\"0\" style=\"width: 100%\">
<tr>
<td style=\"width:26%; text-align: left; font-size: 18px\">
<div>" . $companyName ."</div><br />
<div lang='ja'>" . pll__('Stock Info') ."</div>
</td>
<td class=\"a-center\" style=\"width:26%\">
<div style=\"font-size: 50px; color: #004729; font-weight: bold;\" lang='ja'>" . pll__('Stock Report'). "</div>
</td>
<td style=\"width:26%; text-align: right\">
<div>". $date ."</div><br />
<img src=\"" . ASSETS_URL . "images/logo.png\" width=\"200px\" />
</td>
</tr>
</table>
<table class=\"table\" border=\"0\" cellpadding=\"7\">
<thead>
<tr>
<th class=\"column-header\" style=\"width: 100px\">" . pll__("Col 1") ."</th>
<th class=\"column-header\" style=\"width: 100px\">" . pll__("Col 2") ."</th>
<th class=\"column-header w-150\">" . pll__("Col 3") ."</th>
<th class=\"column-header w-quality\">" . pll__("Col 4") . "</th>
<th class=\"column-header\" style=\"width: 100px\">" . pll__("Col 5") . "</th>
<th class=\"column-header w-80\">" . pll__("Col 6") . "</th>
<th class=\"column-header\" style=\"width: 130px\">" . pll__("Col 7") . "</th>
<th class=\"column-header\">" . pll__("Col 8") . "</th>
<th class=\"column-header\">" . pll__("Col 9") . "</th>
<th class=\"column-header\" style=\"width: 100px\">" . pll__("Col 10") . "</th>
<th class=\"column-header\">" . pll__("Col 11") . "</th>
<th class=\"column-header\" style=\"width: 120px\">" . pll__("Coll 12") . "</th>
<th class=\"column-header w-150\">" . pll__("Col 13") . "</th>
<th class=\"column-header w-150\">" . pll__("Col 14") . "</th>
</tr>
</thead>
<tbody>
";
/** #var StockItem $row */
foreach ($records as $row){
$html .= "
<tr>
<td class=\"cell a-center\">" . $row->col1 ."</td>
<td class=\"cell a-center\">".$row->col2."</td>
<td class=\"cell a-center w-150\">". $row->col3 ."</td>
<td class=\"cell w-quality\">".$row->col4."</td>
<td class=\"cell w-150\">".$row->col5."</td>
<td class=\"cell a-center w-80\">".$row->col6."</td>
<td class=\"cell a-center w-80\">".$row->col7."</td>
<td class=\"cell a-center\" lang='ja'>".$row->col8."</td>
<td class=\"cell a-center\">".$row->col9."</td>
<td class=\"cell a-center\">".$row->col10."</td>
<td class=\"cell a-center\">".$row->col11."</td>
<td class=\"cell a-center w-80\">".$row->col12."</td>
<td class=\"cell a-center w-150\">".$row->col13."</td>
<td class=\"cell cell-last a-center w-150\">".$row->col14."</td>
</tr>";
}
$html .= "
</tbody>
</table>
</body>
</html>
";
return $html;
}
}
Can someone help me with a proper configuration for mPDF or suggest some other configuration with other Japanese font which is already working?
Thanks in advance!
Eventually I've changed the script to use TCPDF and this way has actually worked very nice. I know this answer did not respond to the question I've asked, but it solved my problem.
Hi i m using in my project a simple functionality.
i have a table and some data is fetch data in json file .
Data is coming and if i click to name than edit mode is on if i blur than hide the edit mode and show the view mode is fine i have do this .
now i have a update button if i click to this button than only updated data in insert next row how to do this please check to this and help me .
My code is this
var myApp = angular.module('myApp', []);
myApp.controller('myCntrl', function($scope, $http){
$http.get('js/list.json').success(function(data){
$scope.emplyeList = data;
});
$scope.updateSec= function(employe){
alert("Rohit");
}
});
.click{
cursor: pointer;
text-decoration: underline;
}
.normal-table{
width: 50%;
border-collapse: collapse;
}
.normal-table th{
border: solid 2px rgba(0,0,0,0.1);
}
.normal-table td{
border: solid 2px rgba(0,0,0,0.1);
text-align: center;
padding: 10px 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCntrl">
<body>
<table class="normal-table">
<thead>
<tr>
<th>Name</th>
<th>ID</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employe in emplyeList">
<td>
<div ng-show="!data" ng-click="data=true" class="click">{{employe.name}}</div>
<div ng-show="data"><input ng-blur="data=false" type="text" ng-model="employe.name" /></div>
</td>
<td>
<div ng-show="!data">{{employe.ID}}</div>
<div ng-show="data"><input type="text" ng-model="employe.ID" /></div>
</td>
<td>
<div ng-show="!data">{{employe.add}}</div>
<div ng-show="data"><input type="text" ng-model="employe.add" /></div>
</td>
</tr>
<tr>
<td colspan="3">
<button ng-click="updateSec(employe)">Update</button>
</td>
</tr>
</tbody>
<tbody>
<tr ng-repeat="updatEm in employe">
<td>{{updatEm.name}}</td>
<td>{{updatEm.ID}}</td>
<td>{{updatEm.add}}</td>
</tr>
</tbody>
</table>
</div>
My Json file is
[
{"name":"Rohit", "ID":"5Rt", "add":"Delhi"},
{"name":"Kiran", "ID":"4Kn", "add":"UP"},
{"name":"Abhay", "ID":"3Ay", "add":"HR"},
{"name":"Rahul", "ID":"2Rl", "add":"UK"}
]
HTML
<tr ng-repeat="employe in emplyeList" ng-click="updateSec(employe)">
</tr>
<tr>
<td colspan="3">
<button ng-click="showData()">Update</button>
</td>
</tr>
<tr ng-if="showEmployee" ng-repeat="employe in modifiedEmplyee">
<td>{{employe.name}}</td>
<td>{{employe.ID}}</td>
<td>{{employe.add}}</td>
</tr>
Script
//Display list
$scope.showEmployee = false;
//Create an array to hold updated employee
$scope.modifiedEmplyee = [];
//Set updated field to identify updated employee
$scope.updateSec = function (employe) {
employe.updated = true;
$scope.showEmployee = false;
}
//Show data and copy modilfied list
$scope.showData = function () {
$scope.showEmployee = true;
$scope.modifiedEmplyee = [];
for(var i = 0; i< $scope.emplyeList.length; i++)
{
var emp = $scope.emplyeList[i];
if(emp.updated && emp.updated == true){
$scope.modifiedEmplyee.push(emp);
}
}
}
DEMO
I cannot apply the CSS in the table. For example I want the table to be displayed in the middle and to change the font color and size as well. But I can't. Should I use the tbody tag since I have the body one? Also I generate the table data from database.
<?php
include 'connect.php';
$year = $_POST['year'];
$lecturer = $_POST['lecturer'];
$years = array(
2005,
2006,
2007
);
$lecturers = array(
'lec1',
'lec2',
'lec3',
'lec4'
);
if (in_array($lecturer, $lecturers) && in_array($year, $years)) {
$sql = "SELECT unit_name,a1,a2,a3,l1,l2,r1,r2,u1,u2,u3 FROM $lecturer WHERE year=$year";
$result = mysql_query($sql);
}
else {
echo "No data found";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../statistics/style.css">
</head>
<body>
<div id="mytable">
<table width="900" border="1" cellspacing="1">
<tr>
<tbody>
<td>Unit Name</td>
<td>A1 </td>
<td>A2 </td>
<td>A3 </td>
<td>L1 </td>
<td>L2 </td>
<td>R1 </td>
<td>R2 </td>
<td>U1 </td>
<td>U2 </td>
<td>U3 </td>
</tbody>
</tr>
<?php
while($unit=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$unit['unit_name']."</td>";
echo "<td>".$unit['a1']."</td>";
echo "<td>".$unit['a2']."</td>";
echo "<td>".$unit['a3']."</td>";
echo "<td>".$unit['l1']."</td>";
echo "<td>".$unit['l2']."</td>";
echo "<td>".$unit['r1']."</td>";
echo "<td>".$unit['r2']."</td>";
echo "<td>".$unit['u1']."</td>";
echo "<td>".$unit['u2']."</td>";
echo "<td>".$unit['u3']."</td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
</html>
css:
<!-- principalLecturers
-->
#body{
color:white;
padding-bottom: 20px;
}
#table{
margin:0;
border-collapse: collapse;
color:#b50a1e;
font-family:verdana,arial,sans-serif;
font-size:10px;
}
#table#mytable{
display: table-row-group;
vertical-align: middle;
border-color: inherit
}
I can't see anywhere in your table <table id="table"...>. That's why the styles for #table {...} does not apply.
How to make
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
</tr>
always printable on every page.
My View
<style>
#page { margin: 150px 50px; }
#header { position: fixed; left: 0px; top: -100px; right: 0px; height: 50px; text-align: center; }
#footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; text-align: center; }
#footer .page:after { content: counter(page, upper-roman); }
</style>
<div id="header">
<h1>Tittle</h1>
</div>
<div id="content">
<?php
echo"<table class='gridtable'>";
?>
<table width="100%" page-break-inside: auto;>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
</tr>
<?php
$num = 0;
foreach($result as $key=>$val){
$num++;
echo"<tr>
<td>".$a."</td>".
"<td>".$val['b']."</td>".
"<td>".$val['c']."</td>".
"<td>".$val['d']."</td>".
"<td>".$val['e']."</td>".
"</tr>";
}
?>
</table>
<?php
echo"</table>";
?>
</div>
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(280, 780, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 10, array(0,0,0));
}
</script>
For Example, Here is my PDF after i downloaded
1st page :
| Title 1 | Tittle 2 | Tittle 3 |
| row 1 | row 1 | row 1 |
2nd page :
| row 2 | row 2 | row 2 |
How to make 2nd page like this :
| Title 1 | Tittle 2 | Tittle 3 |
| row 2 | row 2 | row 2 |
I want the Tittle always printed on top every page. Thank You
In recent versions of DOMPDF (e.g., version 0.5.2 or later, I believe), you can wrap your rows containing your table headers in a THEAD.
Change your view to:
<table width="100%" page-break-inside: auto;>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
</tr>
<thead>
This should do the trick. There is one case where it fails: if your table is rendered so that it breaks after your thead but before any data rows are rendered, the thead will not show up on the next page. If the table breaks across yet another page, the thead will show up on the subsequent pages.
This is my code:
<html>
<style>
.left-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#1A5B71;
font-weight:bold;
text-align:right;
}
.right-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#FFFFFF;
font-weight:bold;
text-align:left;
}
</style>
<body>
<table border="1">
<colgroup>
<col class="left-info" />
<col class="right-info" />
</colgroup>
<tr>
<td>3476896</td>
<td>My first HTML</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
</tr>
</table>
</body>
</html>
But, it is showing simple table. Need help !!
Look here
http://www.w3.org/TR/CSS21/tables.html#columns
You can only set border, background, width and visibility with cols
edit
According to MDN, the only allowed attribute on <col> is span. All others are deprecated.
edit
jQuery solution
With this little jQuery snippet you can copy all the class names from the col tags to the corresponding td tags
It works even with colspan in both coland td tags as well as with nested tables.
Example here as jsfiddle
JavaScript
$(document).ready(function() {
var find_TDs_at_COL = function(table, col) {
var ret = [];
$(table).children('tbody').children('tr').each(function() {
var col2 = 0;
$(this).children('td,th').each(function() {
oldCol2 = col2;
if ($(this).attr('colspan')) {
col2 += parseInt($(this).attr('colspan'));
} else {
col2++;
}
if (oldCol2 <= col && col2 > col) {
ret.push(this);
}
})
})
return $(ret);
}
$('table > colgroup').each(function() {
var $table = $(this).parent();
var col = 0;
$(this).children('col').each(function() {
var oldCol = col
if ($(this).attr('colspan')) {
col += parseInt($(this).attr('colspan'))
} else {
col++;
}
for (var i = oldCol; i < col; i++) {
find_TDs_at_COL($table, i).addClass($(this).attr('class'))
}
})
})
})
console.clear()
$(document).ready(function() {
"use strict";
var find_TDs_at_COL = function(table, col) {
var ret = [];
$(table).children('tbody').children('tr').each(function() {
var col2 = 0;
$(this).children('td,th').each(function() {
var oldCol2 = col2;
if ($(this).attr('colspan')) {
col2 += parseInt($(this).attr('colspan'));
} else {
col2++;
}
if (oldCol2 <= col && col2 > col) {
ret.push(this);
}
})
})
return $(ret);
}
$('table > colgroup').each(function() {
var $table = $(this).parent();
var col = 0;
$(this).children('col').each(function() {
var oldCol = col
var that = this
if ($(this).attr('colspan')) {
col += parseInt($(this).attr('colspan'))
} else {
col++;
}
for (var i = oldCol; i < col; i++) {
find_TDs_at_COL($table, i)
.addClass($(this).attr('class'))
// copy style as well
// .each(function() {
// const [ ...style ] = that.style
// for ( let r of style ) {
// this.style[r] = that.style[r]
// }
//})
}
})
})
})
.left-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#1A5B71;
font-weight:bold;
text-align:right;
}
.right-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#00FFFF;
font-weight:bold;
text-align:left;
}
.extra-info {
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#ff0000;
font-style: italic;
text-align:right;
}
.additional-info {
font-size:10px;
font-family:Tahoma, Helvetica, sans-serif;
color:#ffdd00;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1">
<colgroup>
<col class="left-info" />
<col class="right-info" />
<col class="extra-info" colspan="3"/>
<col class="additional-info"/>
<col />
</colgroup>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>C</th>
<th>C</th>
<th>D</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td></td>
<td>Extra</td>
<td>Yes</td>
<td>Add</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>Ugh</td>
<td colspan="2"></td>
<td>Don't trust</td>
</tr>
<tr>
<td>54379</td>
<td>My first JS</td>
<td colspan="2">Trust</td>
</tr>
</table>
VanillaJS solution
{
"use strict";
document.addEventListener('DOMContentLoaded', e => {
Array.from(document.querySelectorAll('table > colgroup')).forEach(cg => {
const table = cg.parentElement
let col = 0
Array.from(cg.querySelectorAll(':scope > col')).forEach(c => {
const oldCol = col
if (c.getAttribute('colspan')) {
col += +c.getAttribute('colspan')
} else {
col++
}
for (let i = oldCol; i < col; i++) {
find_TDs_at_COL(table, i).forEach(el => {
Array.from(c.classList).forEach(c => el.classList.add(c))
})
}
})
})
})
const find_TDs_at_COL = (table, col) => {
let ret = [];
Array.from(table.querySelectorAll(':scope > tbody > tr')).forEach(tr => {
let col2 = 0
Array.from(tr.querySelectorAll(':scope > td, :scope > th')).forEach(tc => {
const oldCol2 = col2
if (tc.getAttribute('colspan')) {
col2 += +tc.getAttribute('colspan')
} else {
col2++
}
if (oldCol2 <= col && col2 > col) {
ret.push(tc);
}
})
})
return ret
}
}
.left-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#1A5B71;
font-weight:bold;
text-align:right;
}
.right-info
{
font-size:14px;
font-family:Tahoma, Helvetica, sans-serif;
color:#00FFFF;
font-weight:bold;
text-align:left;
}
.extra-info {
font-size:24px;
font-family:Tahoma, Helvetica, sans-serif;
color:#ff0000;
font-style: italic;
text-align:right;
}
.additional-info {
font-size:10px;
font-family:Tahoma, Helvetica, sans-serif;
color:#ffdd00;
}
.shadow {
text-shadow: 2px 2px 0 black
}
.info {
text-decoration: overline;
}
<table border="1">
<colgroup>
<col class="left-info" />
<col class="right-info shadow info" />
<col class="extra-info" colspan="3"/>
<col class="additional-info"/>
<col />
</colgroup>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>C</th>
<th>C</th>
<th>D</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td></td>
<td>Extra</td>
<td>Yes</td>
<td>Add</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>Ugh</td>
<td colspan="2"></td>
<td>Don't trust</td>
</tr>
<tr>
<td>54379</td>
<td>My first JS</td>
<td colspan="2">Trust</td>
</tr>
</table>
<br><hr><br>
<table border="1">
<colgroup>
<col class="right-info" />
<col class="left-info" />
<col class="additional-info"/>
<col class="extra-info shadow" colspan="3"/>
<col />
</colgroup>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>C</th>
<th>C</th>
<th>D</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td></td>
<td>Extra</td>
<td>Yes</td>
<td>Add</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>Ugh</td>
<td colspan="2"></td>
<td>Don't trust</td>
</tr>
<tr>
<td>54379</td>
<td>My first JS</td>
<td colspan="2">Trust</td>
</tr>
</table>
Although the answer given here is about a year old at this point, I thought I'd just point out that you can easily do this with very simple CSS
Instead of trying to give the class to every td in its column, you can simply target them like this:
td:first-child{
color: #1A5B71;
text-align: right;
}
td:last-child{
color: #FFFFFF;
text-align: left;
}
Using JavaScript to complete this task is complete overkill
I've written a small jQuery script for this that applies the class to every th and td element in the colspans table.
Try it here
JavaScript:
$(function () {
$('colgroup').each(function () {
var $colgroup = $(this)
var classes = $colgroup.children().map(function () { return $(this).attr('class') })
$colgroup.siblings().children('tr').each(function () {
var col = 0
$(this).children().each(function () {
var $child = $(this)
$child.addClass(classes[col])
col += parseInt($child.attr('colspan')) || 1
})
})
$colgroup.remove()
})
})
The script isn't complicated, but here are the steps:
For every colgroup
cache the classnames that the cols have
For every tr in the same table
set a var col to 0
For every child of tr (ths and tds)
add a class, selected with col
increment col by its colspan attribute or 1 if it isn't present, so that at the next iteration, the script will know what class to select
Remove the colgroup altogether, because you could, for example, have a background that doens't have an opacity of 1, which would result in your ths and tds having a background with the wrong opacity.
I cache $(this) a couple of times, because it is faster to cache jQuery objects than calling $() everytime you want to select an element.