SpreadJS Documentation
Expanding and Collapsing Outlines
SpreadJS Documentation > Sample Code > Sample Code for Range Grouping > Expanding and Collapsing Outlines

You can expand or collapse group outlines with code.

Using Code

This example expands and collapses group outlines.

JavaScript
Copy Code

window.onload = function(){
     var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
     var activeSheet = spread.getActiveSheet();

 activeSheet.suspendPaint();
//Set Outline of row
activeSheet.rowOutlines.group(0, 4);
activeSheet.rowOutlines.group(0, 1);
activeSheet.rowOutlines.group(2, 1);
//Set Outline of column
activeSheet.columnOutlines.group(0, 4);
activeSheet.columnOutlines.group(0, 1);
activeSheet.columnOutlines.group(2, 1);
activeSheet.resumePaint();

$("#button1").click(function(){
// Get the outline label count of the row
         var rgl = activeSheet.rowOutlines.getMaxLevel();
         for(var index = 0; index <= rgl; index++){
             // Expand Outline
             activeSheet.rowOutlines.expand(index, true);
         }

         // Get the outline label count of the column
         var cgl = activeSheet.columnOutlines.getMaxLevel();
         var gi = [];
         var colCount = activeSheet.getColumnCount();
         for(var index = 0, i = 0; index <= cgl; index++){
             for(var col = 0; col < colCount; col++){
                 // Fetch group information of Outline
                 var groupInfo = activeSheet.columnOutlines.find(col, index);
                 if(groupInfo){
                     gi[i] = groupInfo;
                     i++;
                     col = groupInfo.end;
                 }
             }
         }
         for(var i = 0; i < gi.length; i++){
             // Expand outline
             activeSheet.columnOutlines.expandGroup(gi[i], true);
         }
         activeSheet.invalidateLayout();
         activeSheet.repaint();
     });

     $("#button2").click(function(){ 
         // Get the outline row label count
         var rgl = activeSheet.rowOutlines.getMaxLevel();
         for(var index = 0; index <= rgl; index++){
             // Collapse outline
             activeSheet.rowOutlines.expand(index, false);
         }
         // Get the outline column label count
         var cgl = activeSheet.columnOutlines.getMaxLevel();
         var gi = [];
         var colCount = activeSheet.getColumnCount();
         for(var index = 0, i = 0; index <= cgl; index++){
             for(var col = 0; col < colCount; col++){
                 // Fetch group information of Outline
                 var groupInfo = activeSheet.columnOutlines.find(col, index);
                 if(groupInfo){
                     gi[i] = groupInfo;
                     i++;
                     col = groupInfo.end;
                 }
             }
         }
         for(var i = 0; i < gi.length; i++){
             // Collapse Outline
             activeSheet.columnOutlines.expandGroup(gi[i], false);
         }
         activeSheet.invalidateLayout();
         activeSheet.repaint();
     });

                      }

See Also

Developer's Guide