Can I use 'createdrow' callback to modify data in a cell before drawing?

Can I use 'createdrow' callback to modify data in a cell before drawing?

bobg2014bobg2014 Posts: 3Questions: 1Answers: 0
edited June 2014 in Free community support

Hi I am trying to use the Datatables Rows Created Callback to modify the data in the row before drawing it. What I am trying to do is replace all < and > with '<' and '>' so I can put a line break in each cell and have text on separate lines. '\n' or linefeed does 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 can see the data being modified correctly. But its not actually modifying the table. Is there a way to do this? or is the createdRow callback called after the row has already been drawn?

Many thanks.

This question has an accepted answers - jump to answer

Answers

  • bobg2014bobg2014 Posts: 3Questions: 1Answers: 0

    Anybody?

    I know this is probably a simple question, but I've just started using datatables. I'm pretty sure I need to set the rows data to the new data value, I'm just not sure how.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    You can, but in the code above you are manipulating the source data only, not the cell. If you want to modify the cell you need to use html - i.e. br tag, and it would probably be best to use column.createdCell rather than createdRow. If you want to do string manipulation, use column.render.

    Allan

  • bobg2014bobg2014 Posts: 3Questions: 1Answers: 0

    Excellent I'll have a go at your suggestions. Thank you very much!

This discussion has been closed.