Show multiple white spaces in a p-table's cell

UI Components for Angular
Post Reply
magliarov
Posts: 5
Joined: 12 Apr 2018, 13:38

16 Apr 2018, 23:27

Hello
In a dataset that I show in a p-table there're several strings with multiple white spaces. Unfortunately I can't collapse the white spaces into only one. I've tried to use the css style: white-space: pre but it added a lot of white spaces at the begin and at the end of every string and it's makes the table much less readable and usable.
Is there a way to solve the problem without use css style: white-space: pre?

User avatar
Ctrl-C
Posts: 97
Joined: 29 Sep 2016, 04:21

17 Apr 2018, 03:44

Do you want to keep and show whitespace? Can you replace it with   ?

magliarov
Posts: 5
Joined: 12 Apr 2018, 13:38

17 Apr 2018, 19:35

I would like to show white spaces. I've tried to use a pipe to replace ' ' whit ' ' but the special character Entity '' " in the strings were not converted in white spaces.
Ex: for the string "000002150 773" (two white spaces) the output was "000002150  773" (one   and one white space).

the pipe's code is:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'multiSpace'
})
export class MultiSpacePipe implements PipeTransform {

transform(value: String): String {
return value.replace(' ', ' ');
}

}

what do you suggest?
Thanks

User avatar
Ctrl-C
Posts: 97
Joined: 29 Sep 2016, 04:21

17 Apr 2018, 19:40

That's because string.replace by default only replaces first instance.
Try value.replace(/\s/g, " ");

magliarov
Posts: 5
Joined: 12 Apr 2018, 13:38

18 Apr 2018, 09:24

I'm sorry I wasn't clear, the problem is that the charter entity ' ' wasn't converted in a white space: the string was rendered with ' ' instead of ' '.

to be more clear below a screenshot of a cell:

https://imgur.com/5Q0f2oK

User avatar
Ctrl-C
Posts: 97
Joined: 29 Sep 2016, 04:21

18 Apr 2018, 18:04

A little plunker would help. Where were you using 'pre' style? I tried to wrap the td's content in a <span style='white-space:pre'> and that works.

magliarov
Posts: 5
Joined: 12 Apr 2018, 13:38

23 Apr 2018, 13:50

thanks a lot it worked... I tried to put style='white-space:pre' in the div tag that encapsulate the {{}}:

<div *ngIf="col.type!='combo'" style='white-space:pre'>
{{rowData[col.field]}}
</div>

and it added spaces before and after the string. Adding the span tag solved the problem

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests