getRowHeight method - inaccurate height

Posted by: juraj.jakubik on 18 January 2023, 10:16 am EST

    • Post Options:
    • Link

    Posted 18 January 2023, 10:16 am EST

    Hi,

    we use getRowHeight method to calculate the total height of the sheet, but we found out that when we change the row height/font size/… the returned height (in pixels) is inaccurate.

    Is this intended behavior or a bug?

    @grapecity/spread-sheets": “15.2.2,

    @grapecity/spread-sheets-angular”: “15.2.2”

  • Posted 19 January 2023, 3:27 am EST

    Hi,

    We are sorry but we are unable to replicate the issue. Could you please refer to the following code and sample that demonstrates the same and if issue please share a working sample that replicates the issue so that e we could investigate it further and help you accordingly.

    document.querySelector(".fit").addEventListener("click", () => {
      let height = getHeight(spread.getActiveSheet());
    
      //getColumn header height
      let colHeaderHeight = spread
        .getActiveSheet()
        .getRowHeight(0, GC.Spread.Sheets.SheetArea.colHeader);
    
      //get SheetTab height
    
      let sheetTabHeight = document
        .querySelector(".gc-tab-indicator-bottom")
        .closest("table")
        .getBoundingClientRect().height;
    
      let totalHieght = sheetTabHeight + colHeaderHeight + height;
      console.log(sheetTabHeight + colHeaderHeight + height);
    
      spread.getHost().style.height = totalHieght + "px";
      spread.refresh();
    });
    
    function getHeight(sheet) {
      let rC = sheet.getRowCount() - 1;
      let height = 0;
      while (rC >= 0) {
        height += sheet.getRowHeight(rC, GC.Spread.Sheets.SheetArea.viewport);
        rC--;
      }
    
      return height;
    }
    

    sample: https://codesandbox.io/s/green-morning-24c5bx?file=/src/index.js

    Regards,

    Avinash

  • Posted 19 January 2023, 6:18 am EST - Updated 19 January 2023, 6:23 am EST

    Hi,

    please see attached image and https://codesandbox.io/s/nice-lovelace-6hmccu?file=/src/index.js

    Thank you in advance!

  • Posted 20 January 2023, 1:07 am EST

    Hi,

    Thanks for the sample to get the exact height you may use the getCellRect method. Please refer to the following code snippet and attached sample and let me know if you face any issues.

    function initSpread(spread, json) {
      spread.fromJSON(json);
      var sheet = spread.getActiveSheet();
      sheet.resumePaint();
      var pre = document.querySelector("#pre");
    
      let top = getHeight(0) + getHeight(1) + getHeight(2) + 20; //20 is the height of coluHeader
      pre.style.top = top + "px";
      pre.style.height = getHeight(3) + "px";
    
      function getHeight(row) {
        return sheet.getCellRect(row, 0).height;
      }
    }
    

    sample: https://codesandbox.io/s/summer-river-rb1j29?file=/src/index.js:193-607

    regards,

    Avinash

  • Posted 20 January 2023, 5:30 am EST

    Hi,

    thank you, but as you may already know, I need the total height of the sheet.

    getHeight(4/5/6./…) returns undefined.

    Any idea why this is happening?

    Is there any chance for some workaround?

  • Posted 23 January 2023, 2:17 am EST

    Hi,

    We have escalated getRowHeight issue with the concerned team for further investigation… We will update you regarding this as we get any information from the team. The Internal ID for this issue will be SJS-16676.

    Regards,

    Avinash

  • Posted 25 January 2023, 2:04 am EST

    Hi,

    The team infromed us that this is not a bug The sheet has zoom, and the getRowHeight API will return the original row height in the data model, but the getCellRect is used for the rendering.

    So, changing part of the code to below will solve the problem

    [code]let getHeight = (row, sheetArea) => {

    let zoom = sheet.zoom();

    sheetArea = sheetArea || GC.Spread.Sheets.SheetArea.viewport;

    return Math.floor(sheet.getRowHeight(row) * zoom);

    };

    let pre = document.querySelector(“#pre”);

                let top =
                    spread.getHost().offsetTop
                    + getHeight(0)
                    + getHeight(1)
                    + getHeight(2)
                    + getHeight(0, GC.Spread.Sheets.SheetArea.colHeader);
                pre.style.top = top + "px";
                pre.style.height = getHeight(3) + "px";[/code]
    

    Regards,

    Avinash

  • Posted 27 January 2023, 7:17 am EST

    Hi,

    it is not pixel perfect solution, but thank you!

  • Posted 2 February 2023, 2:33 am EST

    HI,

    Thanks for the feedback, but it should give the exact height of the spreadsheet. Could you please share a working sample that shows the pixel differences so that we could investigate it further and help you accordingly?

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels