Line breaks in grid data

3 posts, 1 answers
  1. Mark
    Mark avatar
    90 posts
    Member since:
    Jul 2014

    Posted 30 Dec 2015 Link to this post


    I'm using a client row template to style my grid which is created as follows:


        .DataSource(datasource => datasource
            .Read(read =>
                read.Action("GetJobLogNotes", "TeamsV2").Type(HttpVerbs.Post);
            .Sort(sort => sort.Add("DateCreated").Descending())
        .Columns(columns =>
            columns.Bound(note => note.ItemNo).Title("Ref.").Width(60);
            columns.Bound(note => note.DateCreated).Title("Note Recorded").Width(110);
            columns.Bound(note => note.NoteHtml).Title("Description").Encoded(false);
            columns.Bound(note => note.Employee).Title("Employee").Width(110);
        .HtmlAttributes(new { style = "max-height:496px; height:496px;" })
        .Events(e => e.DataBound("JobLogNotesDatabound"))

    The row template is as follows:

            <a href="/TeamsV2/Search?search=#:data.ItemNo#" style="text-decoration:underline;">#:data.ItemNo#</a>
            #: kendo.toString(data.DateCreated, 'd MMM yyyy HH:mm')#
            #: data.NoteHtml#
            #: data.Employee#
            <br />
            <div class="JobLogEmployeePhoto" data-id="#: data.EmployeeID#">

    The value of "data.NoteHtml" contains "/n" for line breaks as it was inserted via a TextArea.  These /n's are not showing as line breaks in the grid.  I've tried replacing them with HTML so the data contains <br> tags instead but they still do not show.

     My main question is this:  If I modify the data so that the string acxtually contains HTML markup for <BR> or <BR></BR> or <BR /> how can I get the client row template to treat this as HTML instead of just as a string.

     I've set Encoded(false) for the column but still no joy.





  2. Answer
    Kostadin avatar
    1709 posts

    Posted 04 Jan Link to this post

    Hi Mark,

    Thank you for contacting us.

    I would suggest you to try replacing the line breaks "\n" with a "<br>" tag on the client.
    #= changeNewLine(data.NoteHtml) #
     function changeNewLine(text) {
            var regexp = new RegExp('\n', 'g');
            return text.replace(regexp, '<br>');

    Please give this suggestion a try and let me know about the result.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Mark
    Mark avatar
    90 posts
    Member since:
    Jul 2014

    Posted 04 Jan in reply to Kostadin Link to this post

    Worked a treat, thank you.
Back to Top