SpreadJS and autoFit for header row(s)

Posted by: c1_jonc on 8 September 2017, 12:50 am EST

  • Posted 8 September 2017, 12:50 am EST


    I have seen the post in wijmo 3 regarding the fact that the autoFit feature doesn't work for the header row(s) (link -> http://wijmo.com/reply/reply-to-how-can-i-set-autofitrow-for-a-header-row-3/) is this the same case with SpreadJS? I am assuming so.

    I have seen in the documentation a method like "getAutoFitHeight" but I haven't found an example to use for it. Maybe that would provide me with the height information I need?
  • Replied 8 September 2017, 12:50 am EST


    SpreadJS supports AutoFit in columns and rows. AutoFit automatically sizes the column to fit the contents by adjusting the column width or automatically sizes the row to fit the contents by adjusting the row height. You can also include the header text when using AutoFit with the autoFitType method.


    Deepak Sharma
  • Replied 8 September 2017, 12:50 am EST

    Hi Deepak,

    Thank you for the response, but there is something that doesn't make sense there to me, and also the autoFitRow doesn't seem to adjust the height at all.

    In your example you are auto fitting the column 1 before your set the autofittype to cellwithheader. Is that the correct way to do that? Maybe because the autofittype is at the "spread" level it auto adjusts any column that is flagged as "autofit"?

    Secondly, when I use this syntax to do auto row height on the header row nothing happens:

    Attached is a screenshot of the header columns and some of the data. You can see that the columns' width is correct (I did an autofit with just the cell contents before the above code), but the headers do not autofit properly.

  • Replied 8 September 2017, 12:50 am EST


    1. You should set the autoFitType before calling the autoFitRow or autoFitColumn method, so as to autofit the headers along with the rows and columns.

    2. However, as mentioned in the forum link provided by you earlier: http://wijmo.com/reply/reply-to-how-can-i-set-autofitrow-for-a-header-row-3/, the autoFit feature of SpreadJS either changes the height of the viewport rows, including the row header or changes the width of the viewport columns including the column headers to display the complete text. However, it does not supports changing the height of the column header row to display the complete text.

    Further, the argument passed to the autoFitRow method is the index of the viewport row and not the column header row.Hence, the issue that you are currently observing is the intended behaviour of Spread, where in the height of the column header row is not autofit when calling the "autoFitRow" method.

    Further, the "getAutoFitHeight" method is used to get the height of a custom cell and cannot be used in this scenario. So, you would need to manually calculate the height required to display the complete text in the column header and later set the same as the row height by using the “setRowHeight” method.

    Hope it helps.

    Manpreet Kaur
  • Replied 9 February 2021, 2:09 am EST

    Is there any better solution for this since the time of posting?

    And if not - what is the best way to determine approximate height required to display complete text in column header?
  • Replied 9 February 2021, 11:54 pm EST

    Hi Pawel,

    The best way is still to calculate the height manually according to text and then use the setRowHeight for setting the height , Further, have made an enhancement request on your behalf. We will update you regarding the development of this feature. The internal ID for this issue will be SJS- 7607..

  • Marked as Answer

    Replied 18 February 2021, 2:39 pm EST


    The Devs informed us that. Now you may use the autoFit Row Command for the required functionality. Please refer to the following code snippet and let us know if you face any issues.

    cmd: "autoFitRow",
    sheetName: sheet.name(),
    columnHeader: true,
    rows: [{ row: 0 }]

    API References:

    autoFitRow: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Commands~autoFitRow.html?

Need extra support?

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

Learn More

Forum Channels