Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery DataTables - change value of a cell not just display value

Using DataTables I want to change the value of the data before rendering the table. I used this:

"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    if ( aData[2] == "0" ){
        $('td:eq(1)', nRow).html( '<b>6</b>' );
    }
}

But I found that although I changed the displayed text to be 0 to 6, when I sort by the column it's still sorting by the data and not the displayed text.

Does anyone know how I can actually change the data in the cell so that when I sort it will correctly sort by 0-6?

like image 825
Shibbott Avatar asked Jul 21 '10 12:07

Shibbott


2 Answers

You need to update the datatable, not html.

oTable.fnUpdate( newValue, rowPos, columnPos);

assuming oTable is a reference to the datatable.

like image 123
Yisroel Avatar answered Nov 13 '22 06:11

Yisroel


You should probably paste some more of your code, especially the sorting area.

It seems you're mixing up val() and html():

This will get you the input or cell value as in the value tag "value=?"

$("#currentRow").val()

This will get you the actual html (data) between the tag "<td>data</td>"

$("#currentRow").html()
like image 41
Organiccat Avatar answered Nov 13 '22 05:11

Organiccat