15

I'm in a project where I need to use PrimeNG to do tables and I have a problem with defining the width of the first column.

In my HTML code, I have something like:

<p-datatable styleClass="myTable">
     <p-column>

     </p-column>
     ...
</p-datable>

And in my CSS, I have something like:

.myTable td:nth-child(1) {
    width:300px;
}

Also, I've tried with the following HTML:

 <p-datatable>
     <p-column styleClass="col1">

     </p-column>
     ...
 </p-datable>

And in my CSS:

td.col1 {
    width: 300px;
}

And I also did inspect the code and saw the class of the row which is tr.ui-widget-content ui-datatable-even and tried the following CSS:

tr.ui-widget-content ui-datatable-even td:nth-child(1) {
    width: 500px !important;
}

And nothing seems to work.

Can someone tell me if it's possible to define the width of the column and, if so, how can I do that?

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Daniel Serrão
  • 481
  • 1
  • 6
  • 17
  • More reading on overriding angular css: https://www.concretepage.com/angular-2/angular-2-4-component-styles-host-host-context-deep-selector-example – Baked Inhalf Nov 07 '17 at 14:05

2 Answers2

23

You can define the width manually, try this:

<p-column [style]="{'width':'300px'}" </p-column>
David Pascoal
  • 1,431
  • 3
  • 21
  • 26
3

If you are working with angular, you can update css file to change PrimeNg styling with following sample code,

:host /deep/ .ui-datatable{
    width: 500px;
}

For information on Shadow DOM, please refer https://blog.thoughtram.io/angular/2015/06/29/shadow-dom-strategies-in-angular2.html

Prabhakaran M
  • 147
  • 2
  • 8