SpreadJS Documentation
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
$(document).ready(function () {
    var spread = new GcSpread.Sheets.Spread($("#ss").get(0),{sheetCount:3});
    var activeSheet = spread.getActiveSheet();

    activeSheet.isPaintSuspended(true);

    //Set Outline of row
    activeSheet.rowRangeGroup.group(0, 4);
    activeSheet.rowRangeGroup.group(0, 1);
    activeSheet.rowRangeGroup.group(2, 1);

    //Set Outline of column
    activeSheet.colRangeGroup.group(0, 4);
    activeSheet.colRangeGroup.group(0, 1);
    activeSheet.colRangeGroup.group(2, 1);

    activeSheet.isPaintSuspended(false);

    $("#button1").click(function(){
        var activeSheet = $("#ss").data("spread").getActiveSheet();

        // Get the outline label count of the row
        var rgl = activeSheet.rowRangeGroup.getMaxLevel();
        for(var index = 0; index <= rgl; index++){
            // Expand Outline
            activeSheet.rowRangeGroup.expand(index, true);
        }

        // Get the outline label count of the column
        var cgl = activeSheet.colRangeGroup.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.colRangeGroup.find(col, index);
                if(groupInfo){
                    gi[i] = groupInfo;
                    i++;
                    col = groupInfo.end;
                }
            }
        }
        for(var i = 0; i < gi.length; i++){
            // Expand outline
            activeSheet.colRangeGroup.expandGroup(gi[i], true);
        }

        activeSheet.invalidateLayout();
        activeSheet.repaint();
    });

    $("#button2").click(function(){
        var activeSheet = $("#ss").data("spread").getActiveSheet();

        // Get the outline row label count
        var rgl = activeSheet.rowRangeGroup.getMaxLevel();
        for(var index = 0; index <= rgl; index++){
            // Collapse outline
            activeSheet.rowRangeGroup.expand(index, false);
        }

        // Get the outline column label count
        var cgl = activeSheet.colRangeGroup.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.colRangeGroup.find(col, index);
                if(groupInfo){
                    gi[i] = groupInfo;
                    i++;
                    col = groupInfo.end;
                }
            }
        }
        for(var i = 0; i < gi.length; i++){
            // Collapse Outline
            activeSheet.colRangeGroup.expandGroup(gi[i], false);
        }

        activeSheet.invalidateLayout();
        activeSheet.repaint();
    });
});
See Also

Developer's Guide

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.