Cannot convert html special chars to ordinary HTML in jQuery datatable?
Cannot convert html special chars to ordinary HTML in jQuery datatable?
 matt.crawfoord            
            
                Posts: 31Questions: 13Answers: 0
matt.crawfoord            
            
                Posts: 31Questions: 13Answers: 0            
            because the data in jQuery datatable have escaped htmlspecialchars , so I need to convert with escaped htmlspecialchars to a valid HTML code,
i have write a function to do , the function can work ,but cannot convert the data in jQuery datatable
my code ,
<script>
function htmlspecialchars(text) {
 return text
  .replace("&",/&/g )
  .replace("<",/</g )
  .replace(">",/>/g )
  .replace(""",/"/g )
  .replace("'",/'/g );
}
/* htmlspecialchars(d.message) cannot convert  ?????????*/
function format ( d ) {
// `d` is the original data object for the row
return '<table cellpadding="3" cellspacing="0" border="0" style="padding-left:50px;">'+
    '<tr>'+
        '<td>message:</td>'+
        '<td>'+htmlspecialchars(d.message)+'</td>'+
    '</tr>'+
    '<tr>'+
        '<td>Name :</td>'+
        '<td>'+d.user+'</td>'+
    '</tr>'+
'</table>';
}
$(document).ready(function() {
 var table = $('#example').DataTable( {
    "ajax": "process.php,
     "columns": [
        {
            "className":      'details-control',
            "orderable":      false,
            "data":           null,
            "defaultContent": ''
        },
        { "data": "datetime" },
        { "data": "message" }  // and how to convert the child row to a valid HTML code?????????
    ],
    "order": [[1, 'asc']]
} );
// Add event listener for opening and closing details
$('#example tbody').on('click', 'td.details-control', function () {
    var tr = $(this).closest('tr');
    var row = table.row( tr );
    if ( row.child.isShown() ) {
        // This row is already open - close it
        row.child.hide();
        tr.removeClass('shown');
    }
    else {
        // Open this row
        row.child( format( row.data())).show();
        tr.addClass('shown');
    }
} );
} );
  </script>
What are any potential errors that I am overlooking?
Any help will be appreciated !
This question has an accepted answers - jump to answer
This discussion has been closed.
            
Answers
I'm not sure what's wrong with your code. If you link to a test case I'll make some time to look into it.
Allan
what's do you mean test case ?