[{"id":"dc3147d7-d3fb-4bc1-b1b3-142c0633e6d3","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"ca5ca1be-6d75-4ad1-880e-1589e3d52695","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"ea870089-5ea1-499a-bb0c-29cf378ead8d","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"d304d34f-f329-4f3b-b45e-2acb478427f8","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"3a79d24d-b853-4a51-a1e4-361feab06c57","tags":[{"name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce"}]},{"id":"5d31b3db-69bb-4388-9a57-450a63e44456","tags":[{"name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce"}]},{"id":"95e6d892-7bcd-4f6a-a152-504dec37c741","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"ec137f4b-3069-487f-bb0c-69f40fe6805d","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"9a2b2f20-5f3d-43a4-90d0-6f517fd3eebc","tags":[{"name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce"}]},{"id":"8d43dc09-ddd1-4c42-8b02-90765c4c705b","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"a0c3d1e1-4a95-4eaf-808e-93242f2f9aee","tags":[{"name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce"}]},{"id":"bd44c5b0-cd6b-443c-95dc-b8d8054fe1d7","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"fd5ccaa1-50b7-4c33-9ec5-c1eb48317119","tags":[{"name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce"}]},{"id":"ea61139a-0ecf-45ba-83c3-c2f8b20a4126","tags":[{"name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d"}]},{"id":"ca986d5e-dfda-46e9-84f3-f44e4248ab94","tags":[{"name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99","links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce"}]}]
        
(Showing Draft Content)

Dynamic Column Size

SpreadJS provides support for dynamic column sizing (also called star sizing and proportional sizing).


It is used to configure the width of the columns and the height of the rows in such a way that the viewport is filled exactly as per the weighted proportion (represented by the * symbol) specified by the user.


This type of sizing can be used in conjunction with numbers to define a weighted proportion, where:

  • The weighting factor is expressed by using the * (star character) or n* character (n can be any integer value (like 2*, 3* etc.) or a non-integer value (like 0.5* or 1.5* etc.)).

  • Available Size = Viewport Size - Visible Fixed Size.

  • The available size is distributed to the visible row or column as per the weighted factor defined by the user.

  • Total column width = Viewport width.

Usage Scenario

Dynamic Column sizing is beneficial especially when users need to widen multiple columns proportionally in order to analyze reports or manipulate large spreadsheets.


For example - The following image depicts a spreadsheet with dynamic column sizing applied on column A, B and D and E in the proportion of 1.5*, 1.5*, and respectively.




In the above example, columns A and B with a star size "1.5*" are filling 1.5 times that of a standard "*" sized column in the viewport.

Supported User Actions

Dynamic column sizing (or proportional sizing) ensures the columns and rows in a worksheet fill the viewport exactly whenever the viewport size is changed or the user adds, deletes, or resizes any row or column.


Users can configure dynamic column size in the worksheet by using the setColumnWidth and the setRowHeight methods. After applying the dynamic column size, the columns and rows (on which the star sizing is applied) will automatically resize to fill up the viewport when users perform the following actions on the worskheet:

  • Users change the size of the viewport.

  • Users add, delete or resizes any columns or rows in the worksheet.

  • Users change the row count or column count.

  • Users hide or unhide the rows or columns.

  • Users group or ungroup the rows and columns.

  • Users apply filters to the rows and columns.

  • Users expand or collapse the outline columns in the worksheet.

Dynamic Column Sizing is also supported while importing and exporting JSON files.

Dynamic Column Sizing Rules

The following rules must be kept in mind while working with dynamic column size feature in the worksheet:

  • The rows and columns can both be set to star size in one sheet.

  • When users try to resize the star sized row or column, or call the autoFitColumn/autoFitRow methods, then the operated row or column size will overwrite to a fixed number with the actual size.

    In case you're working on the split resize mode (only nextTo mode), then it will overwrite both the operated row or column along with the next row or column size to a fixed number.

  • If the smallest star sizing is <1 (less than 1) or the available size is also <1 (less than 1), then the star size will keep the old size because it will stop calculating the dynamic size.

  • If the users set the star sized row or column to "hidden" or "0*", then the methods getColumnWidth and getRowHeight will return 0.

  • If the users set the star-sized row or column to an invalid string like "abc", it will be treated as the default value.

  • After users zoom the worksheet, the fixed row or column will zoom and the star sizing will stretch to fill the viewport.

  • When the star-sized row or column changes, then any binding objects like shapes, charts, comments, and floating objects in the worksheet will also follow the change.

Note: The following limitations must be kept in mind while working with the dynamic column size feature in the worksheet:

  • The row headers and the column headers don't support dynamic sizing.

  • Because MS Excel doesn't provide support for dynamic column sizing, the dynamic sizing will not be applicable while importing and exporting excel files.

  • While printing to PDF or exporting to excel, it will display the size at view size(old size).

Using Code

Refer to the following example code to configure dynamic column sizing in a worksheet.

$(document).ready(function () {
    // Initializing Spread
    var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });

    // Get the activesheet
    var activeSheet = spread.getSheet(0);
    activeSheet.suspendPaint();
    var colHeader = GC.Spread.Sheets.SheetArea.colHeader;
    activeSheet.setRowCount(12);
    activeSheet.setColumnCount(5);

    // Setting dynamic column sizes
    activeSheet.setColumnWidth(0, "1.5*");
    activeSheet.setColumnWidth(1, "1.5*");
    activeSheet.setColumnWidth(3, "*");
    activeSheet.setColumnWidth(4, "*");
    // Set the row height
    activeSheet.setRowHeight(0, 50, colHeader);
    for (var row = 0; row < 12; row++) {
        activeSheet.setRowHeight(row, "*");
        for (col = 0; col < 5; col++) {
            activeSheet.getCell(row, col)
                .cellPadding('0 0 0 10')
                .vAlign(GC.Spread.Sheets.VerticalAlign.center);
        }
    }
    activeSheet.setValue(0, 0, 'Company Name', colHeader);
    activeSheet.setValue(0, 1, 'City', colHeader);
    activeSheet.setValue(0, 2, 'State', colHeader);
    activeSheet.setValue(0, 3, 'Phone', colHeader);
    activeSheet.setValue(0, 4, 'Fax', colHeader);

    activeSheet.setArray(0, 0, [
        ["Super Mart of the West", "Bentonville", "Arkansas", "(800) 555-2797", "(800) 555-2171"],
        ["Electronics Depot", "Atlanta", "Georgia", "(800) 595-3232", "(800) 595-3231"],
        ["K&S Music", "Minneapolis", "Minnesota", "(612) 304-6073", "(612) 304-6074"],
        ["Tom's Club", "Issaquah", "Washington", "(800) 955-2292", "(800) 955-2293"],
        ["E-Mart", "Hoffman Estates", "Illinois", "(847) 286-2500", "(847) 286-2501"],
        ["Walters", "Deerfield", "Illinois", "(847) 940-2500", "(847) 940-2501"],
        ["StereoShack", "Fort Worth", "Texas", "(817) 820-0741", "(817) 820-0742"],
        ["Circuit Town", "Oak Brook", "Illinois", "(800) 955-2929", "(800) 955-9392"],
        ["Premier Buy", "Richfield", "Minnesota", "(612) 291-1000", "(612) 291-2001"],
        ["ElectrixMax", "Naperville", "Illinois", "(630) 438-7800", "(630) 438-7801"],
        ["Video Emporium", "Dallas", "Texas", "(214) 854-3000", "(214) 854-3001"],
        ["Screen Shop", "Mooresville", "North Carolina", "(800) 445-6937", "(800) 445-6938"]
    ]);

    spread.resumePaint();
});