Predefine column/row count of sheets via option

Posted by: davide.vago on 8 April 2021, 2:17 am EST

    • Post Options:
    • Link

    Posted 8 April 2021, 2:17 am EST

    Dear support,

    I’m trying to understand if there is an option which permits to define a minimum number of columns/rows so when the user hits the add button from the status bar it automatically create new sheets with a defined columns/rows.

    It probably would be within the WorkBook or the WorkSheet classes but I can’t find anything within the documentation.

    Looking forward to hearing from you

  • Posted 8 April 2021, 5:12 pm EST

    Hi Davide,

    We are sorry but currently, there is no is public API available for changing the Worksheet default Row and column count. What you could do is change the row count or column count whenever the new Sheet added(inside the SheetChanged Event). Please refer to the following code snippet and attached sample that demonstrates the same.

    
      spread.bind(GC.Spread.Sheets.Events.SheetChanged, function (sender, args) {
        if (args.propertyName === "insertSheet") {
          setDefaultRowCount(spread.getSheet(args.sheetIndex));
        }
      });
    
    function setDefaultRowCount(sheet) {
      sheet.suspendPaint();
      let defaultRowCount = 10;
      sheet.setRowCount(defaultRowCount);
      sheet.resumePaint();
    }
    
    
    

    Sample: https://codesandbox.io/s/funny-ishizaka-fcmnr?file=/src/index.js

    SheetChanged: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Events~SheetChanged_EV.html

    Regards

    Avinash

  • Posted 8 April 2021, 8:18 pm EST

    Thanks Avinash,

    Would it be possible to expose this option in future releases? It would be a good addition as we don’t need to customise the onSheetChange event (also because the above snippet doesn’t take in consideration pre-existing and pre-populated sheets)

    If anything to cover it up the customisation should be within an “onSheetAdd” or something similar

  • Posted 11 April 2021, 2:39 pm EST

    Hi Davide,

    thanks for the information. We have made an enhancement request on your behalf. We will update you on the development of this feature. The internal ID for this issue will be SJS-8324.

    Regards

    Avinash

  • Posted 12 April 2021, 2:36 pm EST

    Hi Davide,

    The Devs are curious about the use case and also why couldn’t you just set the row/column count after initializing the sheet?

    Regards

    Avinash

  • Posted 5 May 2021, 2:46 am EST

    Hi Avinash,

    By default whenever your SpreadJS instance creates a sheet it generates an X number of predefined columns and rows.

    This number of columns and rows is something that would be really helpful if it could be set via a configuration as the library shouldn’t make the assumption that A-Z columns are enough for a sheet, our use case is:

    If we allow the user to add new sheets and permit them to copy/paste a number of columns/rows from a pre-existing sheet which contains twice the amount of columns, the paste operation fails because there are less columns than what the user has in his own “clipboard”.

    Since our Application has certain instances with more than 40 columns we need to set a minimum of X columns to guarantee to the user the possibility to paste whatever content without having blocking experiences (as per above).

    Setting the number of column after events such as “SheetChanged” is not that clean because you cause a repaint of the canvas just for setting something that should really belong to some sort of “initialisation” options.

    I hope that makes sense.

  • Posted 5 May 2021, 6:50 pm EST

    Hi Davide,

    Thanks for the information. We have shared it with the team. We will update you on the development of the feature.

    Regards,

    Avinash

  • Posted 19 December 2021, 4:52 pm EST

    Hi Davide,

    The Devs informed us that for your use case you could use the following workbook option.

    Please refer to the following code snippet and let me know if you face any issues.

    spread.options.allowExtendPasteRange = true; 
    

    Regards

    Avinash

  • Posted 30 October 2023, 1:29 am EST - Updated 30 October 2023, 1:35 am EST

    Hello Avinash,

    I hope this finds you well. I would like to ask if there’s a possibility to address the original request or to fix the following issue that derives from it:

    • Create a couple of columns and rows beyond the original 20 columns and 200 rows.
    • Create a formula that references a cell within the original 20x200. (e.g. in cell V12 reference A12)
    • Double click on the cell that references A12 to obtain the cell selector.
    • Try selecting U12 by dragging the cell selector from column A.
    • The selection will stop at column T (column 20).
    • Try similarly to drag down to row 202.
    • The selection will stop at row 200.

    This is reproducible in the spreadjs designer demo here: https://www.grapecity.com/spreadjs/designer/index.html

    Best,

    Mihai

  • Posted 30 October 2023, 11:13 pm EST

    Hi,

    For this, You may need to handle the TopRowChanged event and update the rows if the drag fill reaches at the last row. Please refer to the following code snippet and attached sample that explains the same.

     sheet.bind(GC.Spread.Sheets.Events.TopRowChanged, (e, args) => {
        let sheet = args.sheet;
        let rowCount = sheet.getRowCount();
        if (rowCount < sheet.getViewportBottomRow(1) + 15) {
          args.sheet.addRows(rowCount, 10);
        }
      });

    sample: https://codesandbox.io/s/xenodochial-sky-bvxvx?file=/src/index.js

    Regards,

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels