Open Spiceman666 opened 4 years ago
This bug annoys me quite a while now. To reproduce it in the fullscreen example, all i need to do, is to open it on fullsize and reduce the browser width. Afterwards i can scroll into empty space on the right.
Your proposed workaround in ngAfterViewInit didn't work for me though. Got an exception: bodyComponent is 'undefined'
I used a HostListener until this gets fixed
@HostListener('window:resize', ['$event'])
onResize(event) {
// Workaround ngx-datatable #1852
this.table.bodyComponent.scroller.scrollWidth = 0;
}
I had this same issue when trying to make a table work right on smaller screens. It was driving me mad, and I implemented the fixes mentioned here, but they weren't ideal.
Googled once more and came across this https://github.com/swimlane/ngx-datatable/issues/455#issue-202812098.
Try the following for a CSS fix (worked for me, but does not seem to work in the OP's demo):
datatable-scroller {
width: 100% !important;
}
EDIT:
I forgot to remove view encapsulation in the demo, so my CSS changes weren't taking affect.
See here for a fixed fork of OP's demo - though it's possible I'm missing some facet of this problem.
Same problem here, very annoying!
I'm submitting a ... (check one with "x")
Current behavior I have a table with column mode 'force' and horizontal scrolling. If the initial width of the table is greater than the width of all columns, there is no horizontal scrolling. But if you start reducing the width of the table, the scroll appears immediately. This causes an empty space to appear to the right of the columns. Expected behavior Before the horizontal scroll appears, the column width must decrease (to the value of the 'width' or 'minWidth' property, or the default value of 150). Columns must fill the entire width of the table. Reproduction of the problem https://stackblitz.com/edit/angular-eujbw7
You can also see the bug in the official fullscreen demo page: http://swimlane.github.io/ngx-datatable/#full-screen If you have a small screen size, zoom out in the browser and refresh the page. There should not be a horizontal scroll. Then reduce the window width. You can see the empty space to the right of the columns.
What is the motivation / use case for changing the behavior? Columns must fill the entire width of the table.
How to fix: In DataTableBodyComponent, change the calculation of the scroll width. Currently, the width is calculated based on the value' width' of the column, and should be calculated based on the value'$$oldWidth'. It's wrong: [scrollWidth]="columnGroupWidths?.total"
Workaround: @ViewChild('table', {static: true}) table: DatatableComponent; ngAfterViewInit(){ this.table.bodyComponent.scroller.scrollWidth = 0; }
Please tell us about your environment: OS: Windows Package manager: NPM
Table version: 16.0.3
Angular version: 8.0.0
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] Chrome
Language: [all | TypeScript X.X | ES6/7 | ES5] all