API request

Posted by: davide.vago on 11 March 2021, 12:34 am EST

  • Posted 11 March 2021, 12:34 am EST

    Dear support,

    I'm wondering if it could be possible to introduce a new method which permits the developer to get multiple cells based on a selection.

    The getSelections() method permits to return an object like the one within the screenshot:



    In order to get the single cells within a selection the approach we have, at the moment, is looping through the columns and rows, fire the getCell() method and eventually concatenate the output into an array for later use.

    It would really be helpful to have a method e.g. "getCells()" which based on an object containing the information of a selection (col, row, colCount, rowCount) returns an array of cell instances.

    Please let me know if you already have something similar (the current getRange doesn't fit the purpose)

    References:

    Documentation of getSelections()
    (https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Worksheet~getSelections.html?highlight=getselections%2C)

    Documentation of getCell()
    (https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Worksheet~getCell.html)

    Thanks in advance
  • Replied 11 March 2021, 8:17 pm EST

    Hi Davide,

    Could you please explain more about the use case and also is there any issue while looping through the selection? Please provide the following information so that we could have a better understanding of the issue and assist you accordingly.

    Regards
    Avinash
  • Replied 11 March 2021, 9:06 pm EST

    Hi Avinash,

    Sure thing, I'll try to explain what our company use case is as much as I can.

    Our goals are to:
    Given a selection (or a multi selection)
    A) Get value, formula, tag, style for every cell within the selection.
    B) Access single Cells methods to interact from the outside of the workBook instance (other UI components)

    A) We often have to mangle the cell data and generate extra UI components outside the WorkBook

    B) Sometimes our external components need to interact with cells, so we store the coordinates (row, column) and access to the cell methods: (https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.CellRange.html?highlight=cellrange%2C#)

    Our current approach is:
    Loop through the rows and loop through the columns for each row.
    During the process we suspendPaint, suspendCalcService and suspendEvent as we noticed a small performance improvement.

    However, it would be nicer to have some library native method like getArray which permits us to return an array of cells or selective cell data.

    E.g. suppose this new method is named getCells

    we could say
    getCells(selectionObject) => returns an array of CellRange (the Cell instance)
    getCells(selectionObject, { value, formula, style, tag, coords }) => returns an array of the defined options

    Regarding performances, you can check how getArray is way faster and lighter than 2 loops and a getCell().value() or a getValue()

    Thanks
  • Replied 14 March 2021, 4:50 pm EST

    Hi Davide,

    Thanks for the detailed explanation. We have made an enhancement request on your behalf. We will update you on the development of this feature. The internal for this feature will be SJS-7967.

    Regards
    Avinash
  • Marked as Answer

    Replied 26 March 2021, 11:19 pm EST

    Hi Davide,

    The Devs informed us that From the SpreadJS API design point of view, the requirement is not reasonable.

    • The SpreadJS actually don't have a Cell instance, the CellRange type actually is just a util function to help fetch/apply data to the data model, it doesn't store any data on the instance.


    • When SpreadJS design a data API, it should be a self-closing cycle design. for a simple word, you can get, change, then set, but for the customer's request API, it combines different things into one, but once set back, it may break internal logic, because the internal data model may already be changed by other behavior
    • .


    Regards,
    Avinash
Need extra support?

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

Learn More

Forum Channels