SlickGrid icon indicating copy to clipboard operation
SlickGrid copied to clipboard

Problem with measuring column width

Open doornik opened this issue 2 years ago • 2 comments

The getColAutosizeWidth() function sets autoSize.colValueArray in certain cases.

Then getColContentSize() is called. This coerces autoSize.colValueArray to be of type RowInfo in the call to getColWidth.

That coercion means no fields are in common, and nothing is measured. A work around is to replace

    if (autoSize.colValueArray) {
      // if an array of values are specified, just pass them in instead of data
      maxColWidth = this.getColWidth(columnDef, gridCanvas, autoSize.colValueArray as any);
      return Math.max(autoSize.headerWidthPx, maxColWidth);
    }

with

    if (autoSize.colValueArray) {
      // if an array of values are specified, just pass them in instead of data
      const rowInfo = {} as RowInfo;
      rowInfo.startIndex = 0;
      rowInfo.endIndex = autoSize.colValueArray.length - 1;
      rowInfo.valueArr = autoSize.colValueArray;
      maxColWidth = this.getColWidth(columnDef, gridCanvas, rowInfo);
      return Math.max(autoSize.headerWidthPx, maxColWidth);
    }

I use the ability to specify my own value for measuring a column based on colValueArray to get around the inefficiencies inherent in the current implementation of GridAutosizeColsMode.IgnoreViewport.

doornik avatar Nov 29 '23 15:11 doornik

Will have a look at this soon, it's my code. I note I have been meaning to update it for a while, I have my own offline branch and I've fixed a lot of bugs and made a few enhancements over the last 12 months.

6pac avatar Nov 29 '23 22:11 6pac

Just a comment - I got back to this and had a look, but this is a Typescript issue. I'm still pretty sketchy on typescript, so I think if you want assistance it will have to wait a few more months until I do my first major Typescript conversion. Then I'll be up with it - at this point, I'd basically just be guessing. Also, I have uncovered some subtle bugs in the autosize code. It's tricky, because a lot of the autosizing is bound up with what type of editor and formatter is being used in the column and how they behave, and that's often quite complex and completely external to the concerns of the grid. I'm still working that out in my own libraries. TBH a few times I've almost decided to scrap it and go back to a really simple algorithm, and instead provide the ability for the user to set and persist as default the column widths. Having gone this far, I will persist (even if I don't end up using it!), but it will take some hard decisions.

6pac avatar Jan 08 '24 00:01 6pac