Row details with html tags problem

Row details with html tags problem

xfirebgxfirebg Posts: 13Questions: 3Answers: 0

Hello, I get stuck into a problem. I use summernote to store some comments in DB.

I want to display this text in "Row details".

How to render the HTML text?

For example I see it like this in the table:

<p><b>The child row can contain any data you wish, including links, images, inner tables etc.</b></p>

Expected this:

The child row can contain any data you wish, including links, images, inner tables etc.

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Take a look at this example. In the example the format function creates the HTML output for the child rows. You just need to change this function to build the HTML you are expecting.

    Kevin

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    Hello just discover this question and fix. Just I dont understand how this fixed the issue.
    ie.
    '<td>' + $("<span/>").html(d.content).text()+ '</td>' +

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    I guess for that particular case placing the cell data in a span displayed in the child row correctly. That specific solution may or may no be what you want. I add the p and b tags to this example:
    http://live.datatables.net/qolevune/155/edit

    Does this help?

    Kevin

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    To be clear in my case:
    d.name = <p style="line-height: 2;"><strike>asd</strike>&nbsp;<span style="font-size: 18px;"></span></p>
    when I use it like this:
    '<td><p><b>'+d.name+'</b></p></td>'+
    this did not work I see the html tags

    Now if I create variable:
    var name = '<p style="line-height: 2;"><strike>asd</strike>&nbsp;<span style="font-size: 18px;"></span></p>'
    and use it like this:
    '<td><p><b>'+name+'</b></p></td>'+
    its working I dont see html tags.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Please can you update Kevin's test case to demonstrate this - it'll ensure we're both looking at the same thing!

    Colin

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    @colin I don't know how to use to upload /ajax/objects.txt in this example.
    But @kthorngren didn't undestand me fully. For example d.name need to have html tags in it, but he is using html tags outside the variable. Sorry for my english if you did not understand me.
    For example he is using d.name:

    d.name = 'Angelica Ramos'

    '<td><p><b>'+d.name+'</b></p></td>'+

    And want d.name to be:

    d.name = '<p><b>Angelica Ramos</b></p>'

    '<td>'+d.name+'</td>'+

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I'm afraid I don't understand what you are looking for either. If you have the HTML in the name parameter, then just modify the formatter to output only that parameter instead of wrapping it in HTML?

    We'd really need a test case showing what you are trying to do please.

    Allan

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    Hello Allan,
    I use summernote editor. When saving the input in DB all html markups are saved too.
    I just want to render this output later. The problem is that I see the raw html when I get it from DB.

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    How to upload the updated objects.txt in live.datatables.net to show you? Or just add yourself html tags to see...

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    How to upload the updated objects.txt

    There isn't an option for that, but if you just paste in the JSON as a Javascript variable that would at least let me see it.

    Allan

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    Ok Allan,
    I paste it at the top of the JS:
    http://live.datatables.net/qolevune/163/

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    I updated the test case to use the data you supplied:
    http://live.datatables.net/qolevune/164/edit

    Sounds like you don't need to add the additional p and b tags in the format function. I removed those tags. Is this what you are looking for?

    Kevin

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    Oh I see...
    But still I don't understand why doesn't work for me..

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    What exactly isn't working?

    Please provide a link to a test case that shows the issue.

    Kevin

  • xfirebgxfirebg Posts: 13Questions: 3Answers: 0

    Hello Kevin,
    I can create the test case but will be very dificult to represent it because I use Postrgres and Laravel and I have other scripts running.
    But now I discover when json is created, he contain this:
    "name":"&lt;p&gt;&lt;b style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, HelveticaNeue, Verdana, Arial, Helvetica, sans-serif; font-size: 12.6px;&quot;&gt;Doris&lt;\/b&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, HelveticaNeue, Verdana, Arial, Helvetica, sans-serif; font-size: 12.6px;&quot;&gt;&amp;nbsp;&lt;\/span&gt;&lt;u style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, HelveticaNeue, Verdana, Arial, Helvetica, sans-serif; font-size: 12.6px;&quot;&gt;Wilder&lt;\/u&gt;&lt;br&gt;&lt;\/p&gt;"

    And I want to say again, using:
    '<td>' + $("<span/>").html(d.name).text()+ '</td>' +
    from this question the problem is gone.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Yup - looks like your data in the database is HTML encoded. I can't say why that is, but if you want that to display as HTML you'll need to decode it as you have done.

    A better solution would be to track down why it is being HTML encoded in the database (assuming it is, and it isn't a read formatter doing that).

    Allan

Sign In or Register to comment.