jQuery Datatables show html content

SamuGG picture SamuGG · Sep 7, 2012 · Viewed 19.3k times · Source

I have a jquery datatable on my page, which uses server side processing to retrieve data. In this case, one of the columns contains html content, thus my server responses looks like this:

"aaData": [ [1, "aaa", "<span class="myclass">html here</span>" ], ...

I tryed with

"aoColumnDefs": [ "aTargets":[2], "sType": "html" }

But I still see the cell content as if it were plain string. What can I do?

Answer

SamuGG picture SamuGG · Sep 7, 2012

Made a working version with

"aoColumnDefs": [ 
    { "aTargets": [2], 
      "sType": "html", 
      "fnRender": function(o, val) { 
          return $("<div/>").html(o.aData[2]).text();
      } 
    }
]

decoding back the html with jQuery.