I'm storing the column widths of my ngx-datatable inside a database. I get these values using an AJAX call.
How can I set these values for the datatable?
What I've tried:
<ngx-datatable-column>
element@ViewChild(DatatableComponent) table: DatatableComponent;
and setting this.table.bodyComponent.columns[0].width = 500;
this.table.recalculate();
, but nothing seems to work.
EDIT
I'm using datatable-column
with header-template
and cell-template
.
I got it working, though it was very trivial:
I store the width values of the columns in an object
which acts as a dictionary.
The problem was that the grid was rendered before my ajax call has finished and could not make the grid to redraw itself.
So I set the initial value of my dictionary object to null
and put an *ngIf
on the grid: <ngx-datatable *ngIf="colSizes">
This way the rendering happens only after the values of the dictionary are ready to be used.