Skip to content

Instantly share code, notes, and snippets.

@styson
Created January 11, 2011 19:39
Show Gist options
  • Save styson/774980 to your computer and use it in GitHub Desktop.
Save styson/774980 to your computer and use it in GitHub Desktop.
Add ability to select all of the text from a table column.
.columnHighlight { background-color: #9BFF9B; }
.temp { width:100%;margin:.2em 0; }
span.column { display:block;margin:.2em 0; }
h4 { margin:2em 0 .4em 0; }
.helpSpan { font-size:.7em;color:#444; }
.deleteIcon { margin:.-2em .4em; }
function resetColumnSelection() {
$(".temp, .column").remove();
$(".columnHighlight").removeClass("columnHighlight");
}
$(document).ready(function() {
$("<span class='helpSpan'>(double-click a column header to select column text)</span>").insertAfter("hr:eq(2)");
$(".deleteIcon").live("click", resetColumnSelection);
$(".headerRow th").dblclick(function() {
resetColumnSelection()
$th = $(this);
var colIndex = $th.index();
var colData = "";
$th.parents("table").find("tbody tr").each(function() {
var $columnCell = $(this).children("td:eq(" + colIndex + ")");
colText = $.trim($columnCell.text());
$columnCell.addClass("columnHighlight");
if(colText > "") colData += ((colData > "")? ", " : "") + colText;
});
$("<span class='column'>Text from Selected Column:<img src='delete.png' class='deleteIcon'/></span><input type=text class=temp title='text from column' />").val(colData).insertBefore($th.parents("table"));
$(".temp").focus().select();
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment