Open lvidal1 opened 6 years ago
Getting this exact issue - any proper solution?
Here's my fix for it for now (building on the example provided above by @lvidal1 as well as this doc here link http://swimlane.github.io/ngx-datatable/#hidden)
Basically first I wrap the entire datatable in another DOM element, with an *ngIf="isDataLoaded"
on that element. I set that this.isDataLoaded = true
inside the promise i'm subscribing where I load the data so that datatable attempts to load ONLY after data is available (i.e datatable is added to DOM only after data is available)
it looks like if the datatable is loaded first and is bound to blank rows and columns arrays, and then those rows/column array variables are populated later on inside a promise (like inside a subscribed method of an httpclient) then this issue happens -- issue being as said above by @lvidal1 where the header calculation is messed up but if you resize the window slightly headers move to the right place
I am running into this as well - in my case, I am pushing new columns after initialization. To get around the issue, I created an API to get "potential" columns dynamically based on view to be displayed and used "hide/show" to show columns once data is available. @zagros your way might make it easier actually.
Either way still wondering if there is a better solution :)
I'm having an issue similar to this one. In my case, the header not taking up the whole data table area. Interestingly enough, the footer goes all the way across the div, but the header and body do not. Unless I use a button to change a boolean for ngIf after the page loads, it does not fix itself. Even if I change the ngIf's boolean after assigning the incoming data to the table the header and body do not take up the whole div.
Was just looking at the demos and it appears the Hidden On Load example may be demonstrating this bug right now.
Before the data loads the column won't load the min widths, and the header is getting cut off. Any solutions?
Having the same issue when upgrading to 13.1.0, case header width automatically set to 0 when there is a service call after rendering the datatable on screen, any workaround for this scenario instead of setting flag on promise return?
My solution was similar to @zagros but the ngIf did not work for me, I needed to use [hidden]
Wrap the entire datatable in another DOM element, with an [Hidden]="!isDataLoaded" on that element. I set that this.isDataLoaded = true inside the promise i'm subscribing where I load the data so that datatable attempts to load ONLY after data is available (i.e datatable is added to DOM only after data is available).
This worked for me.
<div [hidden]="!isDataLoaded">
You can see using the ngIf in the demo http://swimlane.github.io/ngx-datatable/#hidden the error and the hidden solution works.
I am also facing same issue (Header and body width resetting to zero.)
Any workaround to solve this issue..
I fix this issue using [columnMode]="3"
We cannot assign numbers to columnMode. How did that work for you?
Before the data loads the column won't load the min widths, and the header is getting cut off. Any solutions?
Did you find any solution for that?
I thinkt this might be caused by missing change detection cycles. What you can do is the following:
this.data = [...this.data]
private cd: ChangeDetectorRef
and then after spreading the data to itself, call this.cd.detectChanges()
recalculate()
. You can add a reference using ViewChild to your table and then, somewhat after AfterViewInit you can call this.table.recalculate()
I'm submitting a ... (check one with "x")
Current behavior Datatable header container's width is not calculated but header columns are.
Expected behavior Datatable header container's width should be calculated on render.
Reproduction of the problem When I load a module which has a datatable-component, the header container, which has a class
.datatable-row-center
intodatatable-header
tag, always get awidth:0
. However,datatable-header-cell
tags into the container have their widths calculated.Only when I resize manually the window, datatable runs recalculation an the header container gets a proper width.
I tried this solution and others in this thread, but it seems recalculation runs but header container's width remains with 0.
Snapshot from datatable code rendered
Snapshot from datatable view
Ngx-datatable template
Ngx-datatable columns
What is the motivation / use case for changing the behavior? I want to use datatable on a component into a lazy module
Please tell us about your environment:
Table version: 11.1.5
Angular version: 5.0.3
Browser: Chrome
Language: TypeScript 2.6.1