6pac / SlickGrid

A lightning fast JavaScript grid/spreadsheet
https://github.com/6pac/SlickGrid/wiki
MIT License
1.82k stars 422 forks source link

Problem with measuring column width #934

Open doornik opened 9 months ago

doornik commented 9 months ago

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.

6pac commented 9 months ago

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 commented 8 months ago

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.