Created
January 11, 2011 19:39
-
-
Save styson/774980 to your computer and use it in GitHub Desktop.
Add ability to select all of the text from a table column.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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