SpreadJS Documentation
Adding Unbound Columns

You can add unbound columns to the widget.

Using Code

This example adds unbound columns.

JavaScript
Copy Code
$(document).ready(function () {
    var spread = new GcSpread.Sheets.Spread($("#ss").get(0),{sheetCount:3});
    var activeSheet = spread.getActiveSheet();
    var rowCount, colCount;

    //Create a data table manually.
    var sampleTable = [
        {"Num1":10, "Num2":100, "Num3":1000},
        {"Num1":20, "Num2":200, "Num3":2000},
        {"Num1":30, "Num2":300, "Num3":3000},
        {"Num1":40, "Num2":400, "Num3":4000},
        {"Num1":50, "Num2":500, "Num3":5000}
    ];

    //Bind the data table.
    activeSheet.setDataSource(sampleTable);

    //Add columns (they will become unbound columns).
    activeSheet.addColumns(2, 1);
    activeSheet.addColumns(activeSheet.getColumnCount(), 1);

    //Display a subtotal.
    rowCount = activeSheet.getRowCount();
    activeSheet.referenceStyle(GcSpread.Sheets.ReferenceStyle.R1C1);
    activeSheet.setValue(0, 2, "Subtotal", GcSpread.Sheets.SheetArea.colHeader);                     
    for(var i = 0; i < rowCount; i++){
        activeSheet.setFormula(i, 2, "SUBTOTAL(9, RC[-2]:RC[-1])");
    }
    activeSheet.getColumn(2).backColor("LightCyan");
    activeSheet.getCell(0, 2, GcSpread.Sheets.SheetArea.colHeader).backColor("LightCyan");
    activeSheet.setColumnWidth(2, 60);

    //Display a total.
    colCount = activeSheet.getColumnCount();
    activeSheet.setValue(0, colCount - 1, "Total", GcSpread.Sheets.SheetArea.colHeader);                     
    for(var i = 0; i < rowCount; i++){
        activeSheet.setFormula(i, colCount - 1, "SUBTOTAL(9,RC[-4]:RC[-1])");
    }
    activeSheet.getColumn(colCount - 1).backColor("LightPink");
    activeSheet.getCell(0, colCount - 1, GcSpread.Sheets.SheetArea.colHeader).backColor("LightPink");
    activeSheet.setColumnWidth(colCount - 1, 60);

    //Get the bound state.
    colCount = activeSheet.getColumnCount();
    for(var i = 0; i < colCount; i++){
        if(activeSheet.isColumnBound(i)){
            console.log("Column: " + activeSheet.getValue(0, i, GcSpread.Sheets.SheetArea.colHeader) + " has been bound.");
        }else{
            console.log("Column: " + activeSheet.getValue(0, i, GcSpread.Sheets.SheetArea.colHeader) + " has not been bound.");
        }
    }
});
See Also

Developer's Guide

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.