Skip to content

Instantly share code, notes, and snippets.

@sergebug
Created July 13, 2013 03:51
Show Gist options
  • Save sergebug/5989345 to your computer and use it in GitHub Desktop.
Save sergebug/5989345 to your computer and use it in GitHub Desktop.
Javascript to implement collapsible tables for Finesse.Net. A poor-man imitation of the SLIM goodness.
# Add this script to the PageHeader
# to get an example - uncomment table below.
#|Some Fixture |
#|ignore|This is comment click on it to show hidden line|
#|some method|This line will be hidden |
#|ignore|This is second not hidden line |
#|some method|This is hidden unless you click ... |
#|some method|... on the second not hidden line |
#
#!-<script src="/files/javascript/jquery-1.3.2.min.js"></script>-!
!-
<script>
$(document).ready(function () {
$("tbody>tr>td:first-child:contains('ignore')").addClass("ignore");
$("td.ignore").closest("table").addClass("collapsible"); // All rows are collapsible
$("table.collapsible tbody tr").addClass("collapsible"); // All rows are collapsible
$("tbody tr:first-child").removeClass("collapsible"); // ...except first table row
$("td.ignore").closest("tr").removeClass("collapsible"); // ...and comment row
$("tr.collapsible").toggleClass("hidden"); // Hide all collapsible
$("td.ignore").closest("tr").addClass("expandable"); // Comment row is expandable
// Make it so each of the expandable rows will be highlighted with hidden result
$("tr.collapsible td.pass").each(function() {
$(this).closest("tr").prevAll("tr.expandable:first").find("td:eq(1)").addClass("pass");
});
$("tr.collapsible td.fail").each(function() {
$(this).closest("tr").prevAll("tr.expandable:first").find("td:eq(1)").removeClass("pass").addClass("fail");
});
$("tr.collapsible td.error").each(function() {
$(this).closest("tr").prevAll("tr.expandable:first").find("td:eq(1)").removeClass("pass").removeClass("fail").addClass("error");
});
// Expand All
$("div.collapse_rim a:eq(0)").click(function () {
$("tr.collapsible").removeClass("hidden");
});
// Collapse All
$("div.collapse_rim a:eq(1)").click(function () {
$("tr.collapsible").addClass("hidden");
});
// Table Header
$("table.collapsible tbody tr:first-child").click(function () {
if ($(this).hasClass("expanded")) {
$(this).closest("table").find("tr.collapsible").addClass("hidden");
$(this).removeClass("expanded");}
else {
$(this).closest("table").find("tr.collapsible").removeClass("hidden");
$(this).addClass("expanded");}
});
// Row Handler
$("tr.expandable").click(function () {
//$(this).nextAll("tr.collapsible").toggleClass("hidden");
$(this).nextAll("tr").each( function(){
var row = $(this);
if (row.hasClass("expandable")) return false;
row.toggleClass("hidden");
});
});
});
</script>
-!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment