my iggrid takes in data that has line breaks but it just shows up as one line. how can I make it multi-line with respect to the line breaks?
Hello Jessica,
You should check how this new line is serialized in the JSON string back in the browser. Keep in mind that the FormatterFunction code is executed in the browser.
Best regards,Martin PavlovInfragistics, Inc.
This is actually the code, the <> got replaced somehow in the previous post. It's displaying as "<br/>"
gridModel.Columns.Add(new GridColumn { Key = "Description", HeaderText = "Name", DataType = "string", FormatterFunction = "function(val) {return val.replace(/\\r\\n/g, '<br/>');}", Width = "450px" });
In the database I had this separated with linebreaks
"blahblah"
and this is how it comes in to the code
"blah\r\n blah"
Can you post some example data which is populated in the Description column.You can also try to use the following code:
FormatterFunction = "function(val) {return val.replace('<br/>', '<br/>');}",
So I got part of it working with this
gridModel.Columns.Add(new GridColumn
{ Key = "Description", HeaderText = "Name", DataType = "string", FormatterFunction = "function(val) {return val.replace(/\\r\\n/g, '<br/>');}", Width = "450px" });
However, the <br tag still shows up as "<br/>" and not as a line break. It's still coming in as HTML encoded.
Try with the following code:
Controller code: gridModel.Columns.Add(new GridColumn { Key = "Description", HeaderText = "Name", DataType = "string", FormatterFunction = "replaceLineBreaks", Width = "450px" });
View code:<script type="text/javascript"> function replaceLineBreaks(val) { return val.replace(/\n/g, "<br/>"); }</script>
Hope this helps,Martin PavlovInfragistics, Inc.