Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with measuring column width #934

Open
doornik opened this issue Nov 29, 2023 · 2 comments
Open

Problem with measuring column width #934

doornik opened this issue Nov 29, 2023 · 2 comments

Comments

@doornik
Copy link

doornik commented Nov 29, 2023

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
Copy link
Owner

6pac commented Nov 29, 2023

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
Copy link
Owner

6pac commented Jan 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants