/* // the following can be used to load more complex // scripts and make sure they aren't loaded multiple times // into the page. // however you can't *use* these secondary-load scripts immediately // -- they will fail on the first invocation -- // you could use them in scripted tasks *elsewhere* on the page, // in the same way as the original example in // http://blogs.infosupport.com/reporting-services-javascript-injection/ // showed. But I'd prefer not to have to have two clicks. var scripts = document.getElementsByTagName("script") ; var found = 0 ; for (var i=0; i 0) ) { found = 1; break; } } if (found == 0) { addScript("http://localhost/test/jquery-1.7.1.min.js"); } */ toggle(tObj); function hasInnerText() { // found this here: http://blog.coderlab.us/2006/04/18/the-textcontent-and-innertext-properties/ // I don't know a better way to handle this particular cross-Browser difference: return (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false; } function toggle(tObj) { var tds = document.getElementsByTagName("td"); for (var x = 0; x < tds.length; x++) { var thisAnchor = tds[x].getElementsByTagName("a")[0]; // in my case, I have viewed the source // and I know 1 have only one anchor element child in each // relevant TD element -- so I can test the first anchor // in TD's to see if it follows my header collapse/expand convention // -- your test will vary according to the design of your report. // un-comment the stuff above that loads jQuery, // and you might do the following to get the anchor. // However, it will fail // (won't do anything, or will cause a script error, depending // on which browser & browser settings) // on the first invocation. // var thisAnchor = jQuery(tds[x]).find("a")[0]; var theText; var useInnerText = hasInnerText(); // which browser method do we use? if (useInnerText) { theText = tds[x].innerText; } else { theText = tds[x].textContent; } //The substring expressions below remove my //collapse-expand prefix convention from the text //to create a string telling me what should be appropriate caption for this //group. Again, you have to define your own parsing test depending //on the design of your report: if ((thisAnchor) && theText.substring(2, 300) == tObj) { var newDisplay; var newText; if (theText.substring(0, 1) == "-") { newText = "+ " + tObj; newDisplay = "none"; } else { newText = "- " + tObj newDisplay = ""; } if (useInnerText) { thisAnchor.innerText = newText; } else { thisAnchor.textContent = newText; } // now let's go past the header element // that was clicked for collapse-expand, // and collapse/expand all the rows below it // until we hit another header: for (var xx = 1; xx < (tds.length - x); xx++) { var thisCaptionPrefix; if (useInnerText) { thisCaptionPrefix = tds[xx + x].innerText.substring(0, 1); } else { thisCaptionPrefix = tds[xx + x].textContent.substring(0, 1); } if ((thisCaptionPrefix == "-") || (thisCaptionPrefix == "+")) { // found the next header element break; } else { tds[xx + x].style.display = newDisplay; } } break; } } }