question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable header width is not calculated

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:13
  • Comments:11

github_iconTop GitHub Comments

5reactions
zagroscommented, Jan 14, 2018

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

1reaction
tinyweaselcommented, Aug 1, 2018

Before the data loads the column won’t load the min widths, and the header is getting cut off. Any solutions?

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

datatable jquery - table header width not aligned with body width
Most likely your table is hidden initially which prevents jQuery DataTables from calculating column widths. SOLUTION. If table is in the collapsible element, ......
Read more >
FixedHeader column width not calculating properly with multi ...
Quite late to this party... since it seems that FixedHeader is only applying the column widths to the first row of the header;...
Read more >
DataTables autoWidth Option - GeeksforGeeks
The autoWidth option is used to specify whether the automatic calculation of the column width in the DataTable is enabled or not.
Read more >
DataTable Width & Column Width - Dash Plotly
The width of the columns is determined automatically in order to accommodate the ... In the example above, ellipsis are not displayed for...
Read more >
DataTables Options - GitHub Pages
... The option autoWidth is set to FALSE by default, so that DataTables does not calculate and put hard-coded width values on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found