Advertisement
Guest User

Cognos Tree View

a guest
Jan 18th, 2011
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. On the top of the page:
  2. <script>
  3. //var count=1;
  4. //  These settings you can change to modify the report processing
  5. var UOM="px";       // Set to unit of measure for padding
  6. var INDENT_SIZE=15;     // Set to indent padding step size.  i.e setting to 20 means the padding steps are 20,40,60,80, etc
  7.  
  8. var UOM_SIZE = UOM.length;
  9.  
  10. function stripTrailing(string,num) {
  11.     if ( string == "") {return parseInt(0);} else {return parseInt(string.substring(0,string.length-num));}
  12. }
  13.  
  14. function ExpandCollapse( el )
  15. {
  16.     // Grab the ROW that was clicked and the TABLE that contains it
  17.  
  18.     var tr = el.parentElement.parentElement;
  19.     var tbl = tr.parentElement.parentElement;
  20.  
  21.     // Set the alternating display values for hiding/showing the row
  22.  
  23.     var sDisplay = ( el.src.indexOf( "minus" ) == -1 ) ? "" : "none";
  24.     var sDisplayReverse = ( el.src.indexOf( "minus" ) == -1 ) ? "none" : "";
  25.  
  26.     //Switch the icon for the clicked row
  27.  
  28.     el.src = "../Webfiles/ProjectFolder/PropertyGroup_" + ( el.src.indexOf( "minus" ) == -1 ? "minus" : "plus" ) + ".gif";
  29.  
  30.     // Starting with the row below the clicked row, start checking each row
  31.  
  32.     for ( var i = tr.rowIndex + 1; i < tbl.rows.length; i++ )
  33.     {
  34.  
  35.         // Set the Current row indicator nad the left padding value
  36.         var trCurrent = tbl.rows( i );
  37.         var trCurrentLeft = trCurrent.cells(0).style.paddingLeft;
  38.  
  39.     /*  if(tbl.rows(i+1)){
  40.             if(tbl.rows(i+1).cells(0).style.paddingLeft < trCurrentLeft+1){
  41.                 trCurrent.cells(0).getElementsByTagName("IMG").item(0).src = "../Webfiles/ProjectFolder/blank.gif";  
  42.                 trCurrent.cells(0).getElementsByTagName("IMG").item(0).onclick = "javascript: void(null);";
  43.                 trCurrent.cells(0).getElementsByTagName("IMG").item(0).style.cursor = "point";
  44.             }
  45.         }*/
  46.  
  47.         // if the current row contains an IMG in it, it's a clickable level and we either have to stop processing,
  48.         //     or reset the icons to a + as it's being collapsed
  49.         if ( trCurrent.cells( 0 ).firstChild && trCurrent.cells( 0 ).getElementsByTagName( "IMG" ).length )
  50.         {
  51.  
  52.  
  53.             // If the current row is at the same level or above in the tree, then stop processing,
  54.             //    else reset all the signs below it, essentially collapsing all branches underneath the one that is beig collapsed.
  55.  
  56.             if (  stripTrailing(trCurrentLeft , UOM_SIZE) <= stripTrailing(tr.cells(0).style.paddingLeft , UOM_SIZE) )
  57.             { break; }
  58.             else
  59.             {
  60.                 if (el.src.indexOf( "minus" ) == -1 )
  61.                 {
  62.                     trCurrent.cells(0).getElementsByTagName("IMG").item(0).src = "../Webfiles/ProjectFolder/PropertyGroup_plus.gif";
  63.                 }
  64.             }
  65.         }
  66.  
  67.         // Now, we determine if the row should be hidden or shown.
  68.         if ( eval(stripTrailing(tr.cells(0).style.paddingLeft, UOM_SIZE)+ INDENT_SIZE) < stripTrailing(trCurrentLeft, UOM_SIZE) && el.src.indexOf( "minus" ) >0 )
  69.         {
  70.             trCurrent.style.display = sDisplayReverse;
  71.         } else
  72.         {
  73.             trCurrent.style.display = sDisplay;
  74.         }
  75.     }
  76. }
  77.  
  78.  
  79. function StartHidden(el){
  80.  var tbl=el.parentElement.parentElement.parentElement.parentElement;
  81.  var topo=document.getElementById("topo");
  82.  for (var i = 0; i < tbl.rows.length; i++){
  83.   var trCurrent = tbl.rows(i);
  84.   if (trCurrent.cells(0).style.paddingLeft.indexOf(UOM) > -1){
  85.    trCurrent.style.display = "none";
  86.   }
  87.  }
  88.  el.src= "../Webfiles/ProjectFolder/PropertyGroup_plus.gif";
  89. topo.src = "../Webfiles/ProjectFolder/PropertyGroup_plus.gif";
  90. }
  91.  
  92.  
  93. function ShowAll(el){
  94.  var tbl=el.parentElement.parentElement.parentElement.parentElement;
  95.  var topo=document.getElementById("topo");
  96.  
  97.  for (var i = 0; i < tbl.rows.length; i++){
  98.     var trCurrent = tbl.rows(i);
  99.  
  100.     if (trCurrent.cells(0).style.paddingLeft.indexOf(UOM) > -1){
  101.         //if(trCurrent.cells(0).innerHTML != "")
  102.         //{
  103.             trCurrent.style.display = "";
  104.         trCurrent.cells(0).getElementsByTagName("IMG").item(0).src = "../Webfiles/ProjectFolder/PropertyGroup_minus.gif";
  105.         //}
  106.  
  107.  
  108.     }
  109.  
  110.  }
  111.  
  112. el.src= "../Webfiles/ProjectFolder/PropertyGroup_minus.gif";
  113. topo.src = "../Webfiles/ProjectFolder/PropertyGroup_minus.gif";
  114.  
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. /*
  123. if(count == 1){
  124.     StartHidden(document.getElementById("imgHidden"));
  125.     count++;
  126. }*/
  127. </script>
  128.  
  129. For top row of the table, create 2 HTML Itens:
  130. //First
  131. <img onclick='(this.src.indexOf("_plus")!=-1)?ShowAll(this):StartHidden(this)' src='../Webfiles/ProjectFolder/PropertyGroup_minus.gif' style='cursor:hand; vertical-align:middle; margin-right:2px' /> Colapse/Expand All</br><hr>
  132.  
  133. //Secound
  134. <img id='topo' name='topo' onclick='ExpandCollapse(this)' src='../Webfiles/ProjectFolder/PropertyGroup_minus.gif' style='cursor:hand; vertical-align:middle; margin-right:2px'/>       
  135.  
  136. For every row on the table:
  137. <img onclick='ExpandCollapse(this)' src='../Webfiles/ProjectFolder/PropertyGroup_minus.gif' style='cursor:hand; vertical-align:middle; margin-right:2px'/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement