ngx-datatable: Data table doesn't shrink when window is resized
I’m submitting a … (check one with “x”)
[ x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter
Current behavior When rendering the datatable in a view and not absolutely positioned, the initial width is set and making the window larger triggers a resize, but shrinking it does not.
Expected behavior It would re-render the width for enlarging and shrinking window.
Reproduction of the problem I’ll try to get a plunker up but it’s entirely possible that there something else causing this that is specific to my app.
What is the motivation / use case for changing the behavior?
Please tell us about your environment: Mac, Chrome latest, Webstorm
-
Table version: 0.8.x Latest
-
Angular version: 2.0.x 4.4
-
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]
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 22
- Comments: 28
I Think i solved the hard way. Just add these Lines in your CSS Rules :
This will keep the header and body of the table on a good shape. I recommend to wrap the datatable on a div using the
.table-responsiveclass from bootstrap. it will work better for responsive.Invoke the below method on sidebar minimizer
(click)=“WindowResize($event)”
WindowResize(e) {
setTimeout(() => { window.dispatchEvent(new Event(‘resize’)); }, 250); }
I have resolved it by adding
overflow: auto;at parent div.I found that adding
.datatable-row-detail { width: 100vw; }to a css file like main.css fixed the issue!I am having the same issue with ngx data table. When I expand my browser window, the columns seem to stretch fine, but when I make the browser window smaller, the columns don’t spring back with the window. I have been fixing it for more than 2 days now. Any methods to get a work around? Or maybe I am better off with a different data table component?
I found the solution to the issue.
Just use rxjs delay operator in ngOnit to call ngx-datatable’s recalculate function.
I implemented this on a button click so when that toggle button is clicked i emit a val ( can be anything) from my navService and subscribe to it in the component in which you are using the datatable. Use the snippet below in ngOnit.
this.navService.testingSubject.pipe(delay(500)).subscribe((val) => { this.table.recalculate(); });
Thanks
After 2 hours of trying, this is what did it! Thank you!
@lrochaoliveira please have a look. At least at my side this test grid resizes normally. But you might have a more complex scenario, in this case this code needs to be adjusted. I even don’t remember the details and it was done for some old version of Swimlane Datatable, plus I had a newer Angular than you… Maybe the code needs to be retrofitted now. Anway, let me know if this at least works for you “as is” 😉
@lrochaoliveira ok - i will try to do that today later on.
Hi,
My ngx-datatable doesn’t shrink and columns go out of the window when enlarge the browser window. I tried all methods described above. None worked. Because it is told resizing issue fixed, I updated datatable to its last version . But it didn’t work as well. Do you have any other idea about how to solve this problem? Thanks.