Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Datatables show html content

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?

like image 413
SamuGG Avatar asked Sep 07 '12 14:09

SamuGG


2 Answers

You need to just add below line before rawColumns() or make(true)

->escapeColumns('aaData')

Use this method and pass column name thats'it

like image 125
Jignesh Patel Avatar answered Oct 10 '22 17:10

Jignesh Patel


I update SamuGG's answer, for new datatable version:

"aoColumnDefs": [ {
                     "aTargets": [ 5 ],
                     "mRender": function ( data, type, full ) {
                      return $("<div/>").html(data).text(); 
                      }
            } ]
like image 34
Maforast Avatar answered Oct 10 '22 18:10

Maforast