Which method is most best to add the HTML in rows?
Which method is most best to add the HTML in rows?

Hello!
Which method is most best to add the HTML in rows?
I need add HTML tag in column for every rows the client-side from server-side response.
Example <span class="danger">Test</span>.
With help ajax.dataSrc ?
$('#example').dataTable( {
"serverSide": true,
"ajax": {
"url": "data.php",
"dataSrc": function ( json ) {
for ( var i=0, ien=json.data.length ; i<ien ; i++ ) {
json.data[i][0] = '<span class="danger">'+json.data[i][0]+'</span>';
}
return json.data;
}
}
} );
Or has another way to the most best and fastest? Or ajax.dataSrc the only way?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I would suggest you use a renderer.
Allan
Allan, thank you!
Renderers better than ajax.dataSrc ?
For this yes.
ajax.dataSrc
is useful for modifying the structure of the JSON, but for modifying the output data I would certainly recommend a renderer. That way any changes made via the API in future (cell().data()
for example) would be reflected through the renderer.Allan
Ok! Thank you very much!