2

I've coded a PrimeFaces (JSF / Java) p:dataTable that uses p:inputNumber for each cell. Everything works, but the table looks ragged due to the left-alignment of p:inputNumber's content. All of the formatting I've tried formats the control itself, not its content.

Is there any way to right-align the content of a p:inputNumber?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Stuart Wilson
  • 89
  • 1
  • 6

4 Answers4

6

If someone in 2020 or later is visiting this page:

For PrimeNG 10 the Angular ngStyle Syntax is needed for input style. Just do the following:

<p-inputNumber [(ngModel)]="0.00" [inputStyle]="{'text-align': 'right'}"></p-inputNumber>

Update 2023:

The above is still a possibility. But when using primeflex I like this solution better, using the already available 'text-right'-class:

<p-inputNumber [(ngModel)]="0.00" inputStyleClass="text-right"></p-inputNumber>
J-Eibe
  • 152
  • 4
  • 12
5

For inputNumber there are attributes inputStyle and inputStyleClass.

I managed to get my number input's right aligned like this:

<p:inputNumber value="0.00" inputStyle="text-align: right" />
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Osmund Francis
  • 771
  • 10
  • 27
2

I would do something like

span.ui-inputnumber > input[type=text] {
    text-align: right;
}

That should catch all p:inputNumber's everywhere.

Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
1

In 2021 with angular 11 and primeng v11.3.2 @J-Eibe answer is still valid if you just want to style a single p-inputNumber, but if you want some more generic, place the following code in your style.css

.p-inputnumber-input{
  text-align: right;
}
Biiz
  • 349
  • 4
  • 18