Ngx-datatable: Datatable header width is not calculated

Created on 5 Dec 2017  路  9Comments  路  Source: swimlane/ngx-datatable








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
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 into datatable-header tag, always get a width: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
seleccion_097

Snapshot from datatable view
seleccion_096

Ngx-datatable template

<ngx-datatable ngx-resize-watcher
      class="material minimal"
      [columnMode]="'force'"
      [rows]="rows"
      [columns]="columns"
      [messages]="messages"
      [rowHeight]="40"
      [headerHeight]="38"
      [footerHeight]="0"
      [scrollbarV]="false"
      >
</ngx-datatable>

Ngx-datatable columns

const columns = [
            { prop: 'nro', name: 'Nro.' , width: 50, headerClass: 'text-center border', cellClass: 'text-center border'},
            { prop: 'condicion' , name: 'Condicion',  width: 150, headerClass: 'text-center border', cellClass: 'text-center border capitalize'},
            { prop: 'dni' , name: 'DNI', width: 150, headerClass: 'text-center border', cellClass: 'text-center border'},
            { prop: 'apaterno' , name: 'Apellido Paterno', width: 150, headerClass: 'text-center border', cellClass: 'text-center border'},
            { prop: 'amaterno' , name: 'Apellido Materno', width: 150, headerClass: 'text-center border', cellClass: 'text-center border'},
            { prop: 'nombres' , name: 'Nombres',  width: 150, headerClass: 'text-center border', cellClass: 'text-center border'},
            { prop: 'acciones', name: 'Acciones', width: 150,  headerClass: 'text-center border',
              cellClass: 'text-center border', cellTemplate: this.actionsTable}
      ]

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

Most helpful comment

__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

All 9 comments

__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?

image

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.

.....

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"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eddy-geek picture eddy-geek  路  3Comments

TakhirMamirov picture TakhirMamirov  路  3Comments

JanStock picture JanStock  路  3Comments

dinvlad picture dinvlad  路  3Comments

mmrath picture mmrath  路  3Comments