Why is my jquery datatables createdrow function not working?

I am trying to use Datatables Rows Created Callback to modify the data in a string before drawing it. What I'm trying to do is to replace all &lt;, and &gt;on '<', and '>'so I could put a line break in each well and have text on separate lines. '\n'or linefeeddoes not work.

var oTable = $('#table').DataTable( { 
      "createdRow" : function( row, data, index) {
         console.log( 'DATA WAS ' + data[0]);
         data[0] = data[0].replace(/&lt;/g,'<').replace(/&gt;/g,'>');
         console.log( 'DATA IS ' + data[0]);
       }

in the console, I see the correct data changes. But actually this is not a table change. Is there any way to do this? or is the createRow callback called after a line has already been drawn?

+4
source share
2

, . createdRow callback , . , , , , (?), defs: D /, -, &lt;.

var oTable = $('#table').DataTable( { 
    "columnDefs": [ {
        "targets": 0,
        "render": function(data, type, row, meta) {
            html = data.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
            return html;
        },
    ],
}
+3

td ().

var oTable = $('#table').DataTable( { 
    "createdRow" : function( row, data, index) {
    console.log( 'DATA WAS ' + data[0]);
    data[0] = data[0].replace(/&lt;/g,'<').replace(/&gt;/g,'>');
    console.log( 'DATA IS ' + data[0]);
    $('td', row).eq(0).append(data[0]);
}
0

Source: https://habr.com/ru/post/1544570/


All Articles