Height of rows with wordwrapped cells do not shrink when cell is made empty

Posted by: brian.couckuyt on 25 January 2022, 5:58 pm EST

    • Post Options:
    • Link

    Posted 25 January 2022, 5:58 pm EST - Updated 30 September 2022, 2:39 am EST

    In Spread.NET in an ASP.NET MVC 5 application,

    when setting multiline and wordwrap of a cell to true, the row height scales when entering text in the cell. However, when making the cell empty afterwards, the row stays at the height it was when the cell was filled with text.

    assigning a TextCellType to the cell and setting AllowWrap and Multiline to true :

    after emptying the cell of it’s text :

    Is there any way to make the row height resize to it’s default size (or a new height to match the cell’s new text height)?

    Thanks in advance.

  • Posted 25 January 2022, 8:19 pm EST

    As extra info; we know that a spread.update would solve this, but because of performance issues this is not an option in our case.

  • Posted 27 January 2022, 5:29 pm EST

    Hi,

    We are sorry but this is by design. Spread.net does not change the height dynamically. Fort this you need to calculate the Text height by yourself and set it inside the EditStopped event. please refer to the following code snippet and let me know if you face any issues.

    
     var spread1 = document.getElementById("<%=FpSpread1.ClientID %>");
            if (document.all) {
                // IE
                if (spread1.addEventListener) {
                    // IE9
                    spread1.addEventListener("EditStopped", cellChanged, false);
                } else {
                    // Other versions of IE and IE9 quirks mode (no doctype set)
                    spread1.onEditStopped = cellChanged;
                }
            }
            else {
                spread1.addEventListener("EditStopped", AutoFitRow, false);
            }
            
    
            function AutoFitRow(event) {
                let spread = event.spread
                spread1.setRowHeight2(spread.ActiveRow, getHeight(spread.ActiveRow, spread));
            }
    
            function getHeight(row,spread) {
                let height = -1
                for (let i = 0; i < parseInt(spread1.ColCount); i++) {
                    let colHeader = spread.getColHeader(0);
                    let columnWidth = colHeader.querySelectorAll("td")[i].getBoundingClientRect().width
                    let divEle = document.createElement("div")
                    divEle.textContent = spread.Cells(row,i).textContent;
                    divEle.style.width = columnWidth + "px";
                    divEle.style.height = "fit-content";
                    document.body.appendChild(divEle)
                    height = Math.max(height, divEle.getBoundingClientRect().height);
                        divEle.remove()
                }
                return height;
            }
    
    

    Regards,

    Avinash

  • Posted 6 February 2022, 8:00 pm EST

    Hello Avinash,

    This solution worked for us.

    Thank you for the assistance.

    With regards,

    Brian

Need extra support?

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

Learn More

Forum Channels