Row details with html tags problem
Row details with html tags problem
xfirebg
Posts: 13Questions: 3Answers: 0
in DataTables
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
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
Hello just discover this question and fix. Just I dont understand how this fixed the issue.
ie.
'<td>' + $("<span/>").html(d.content).text()+ '</td>' +
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 thep
andb
tags to this example:http://live.datatables.net/qolevune/155/edit
Does this help?
Kevin
To be clear in my case:
d.name = <p style="line-height: 2;"><strike>asd</strike> <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> <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.
Please can you update Kevin's test case to demonstrate this - it'll ensure we're both looking at the same thing!
Colin
@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
:'<td><p><b>'+d.name+'</b></p></td>'+
And want
d.name
to be:'<td>'+d.name+'</td>'+
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
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.
How to upload the updated
objects.txt
inlive.datatables.net
to show you? Or just add yourself html tags to see...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
Ok Allan,
I paste it at the top of the JS:
http://live.datatables.net/qolevune/163/
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
andb
tags in the format function. I removed those tags. Is this what you are looking for?Kevin
Oh I see...
But still I don't understand why doesn't work for me..
What exactly isn't working?
Please provide a link to a test case that shows the issue.
Kevin
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":"<p><b style="font-family: &quot;Helvetica Neue&quot;, HelveticaNeue, Verdana, Arial, Helvetica, sans-serif; font-size: 12.6px;">Doris<\/b><span style="font-family: &quot;Helvetica Neue&quot;, HelveticaNeue, Verdana, Arial, Helvetica, sans-serif; font-size: 12.6px;">&nbsp;<\/span><u style="font-family: &quot;Helvetica Neue&quot;, HelveticaNeue, Verdana, Arial, Helvetica, sans-serif; font-size: 12.6px;">Wilder<\/u><br><\/p>"
And I want to say again, using:
'<td>' + $("<span/>").html(d.name).text()+ '</td>' +
from this question the problem is gone.
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