cancel
Showing results for 
Search instead for 
Did you mean: 

how do I display \n in sap.m.Text

former_member182862
Active Contributor
0 Kudos
4,122

this appears to be a simple thing but...

JS Bin - Collaborative JavaScript Debugging

I wish to text control to show \n.

Thanks

-D

Accepted Solutions (1)

Accepted Solutions (1)

former_member183518
Active Participant
0 Kudos

just a hack.


new sap.ui.model.json.JSONModel({

  a: '\\\rn'

});

JS Bin - Collaborative JavaScript Debugging

former_member182862
Active Contributor
0 Kudos

Thanks Everyone.

I love almost all your suggestions. Sakthivel's hack is outstanding 😉

Answers (3)

Answers (3)

Former Member
0 Kudos

Not exactly the required output. But will this help?

JS Bin - Collaborative JavaScript Debugging

Former Member
0 Kudos

Hi Dennis,

Can you please try 2 things :

1. change the control from sap.m.Text to sap.m.Label.

2. write a formatter for the text property to replace the escape chatacters :

eg :

//VIEW ->

<Label text="{path:'/textValue', formatter:'.formatStringData'}"></Label>

//CONTROLLER ->

formatStringData : function(stringValue){

var str = "";

  if(stringValue){

       str = stringValue.replace("\n","\\n");

  }

  return str;

  }

Best Regards

Deepshikha

former_member182374
Active Contributor
0 Kudos

Hi Dennis,

The renderer uses writeEscaped so '\n' turns to new line.

If you add some text before and after the \n you'll see the new line. Is it OK for you?

If not, you can override the sap.m.Text control and 'escape' it the way you want.

Regards,

Omri

former_member182862
Active Contributor
0 Kudos

Thanks for your answer Omri.

I do not want newline. I want to see 1\n2 displayed.

I have to have writeEscape to avoid javascript injection.

-D

venkatachala_ck
Active Participant
0 Kudos

Hi Dennis,

I saw your code and i tried it was not coming

but i got one bad idea  .

var m = new sap.ui.model.json.JSONModel({

  a: "\\ n"

});

it will print \ n ( \ space n),

if you got better idea please let me know..

Thanks & Regards

Venkat