Javascript Array Source: Using HTML tags?

Javascript Array Source: Using HTML tags?

spierceyspiercey Posts: 2Questions: 0Answers: 0
edited July 2012 in General
Hello all, I am using a 2d array of strings for my data source and I am trying to add a few html tags to some of the columns. However the html seems to be ignored and the tags are just added as plain text to the table. For example:

[code]
$('#listTable').html( '' );
$('#example').dataTable( {
"aaData": [
["Testing", "Table", "1"],
["Test", "The", "table"]
],
"aoColumnDefs":
[
{ "aTargets": [ 0 ], "sType": "html", "sTitle": "First"},
{ "aTargets": [ 1 ], "sTitle": "Second"},
{ "aTargets": [ 2 ], "sTitle": "Third"},
]
} );
} );
[/code]

I want Testing to be boldface and Test to be a link to google.com. However in the table the tags just appear as plain text. Is what I want possible?

Thanks,
Stephen

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Absolutely possible, but this:

    [code]
    "Test"
    [/code]

    is not a valid Javascript string. In fact it will cause a syntax error, since there are two strings with www.google.com in-between them.

    Escape the "inner" quotes:

    [code]
    "Test"
    [/code]

    Allan
  • spierceyspiercey Posts: 2Questions: 0Answers: 0
    Ah, yes of course. That was just a quick example. Though it still does not render as a link and does not explain why the bold face is not working?
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Can you link to a test case showing the problem please?
This discussion has been closed.