views:

132

answers:

2

Hi

i am fairly new to jquery DataTables.Hope someone can help

What I want to do is change the value of the data before rendering the table, I used this below

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

But I found that although I change the display of any data with 0 to 6, when i sorted by the column is still sort by the data not the display.

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

Please let me know if i am not making myself clear

Thanks

A: 

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()
Organiccat
Hi there "fnRowCallback": function( nRow, aData, iDisplayIndex ) { if ( aData[2] == "0" ){ $('td:eq(1)', nRow).html( '<b >2</b>' ); nRow }else if ( aData[2] == "1" ){ $('td:eq(1)', nRow).html( '<b >1</b>' ); }else if ( aData[2] == "2" ){ $('td:eq(1)', nRow).html( '<b>0</b>' ); return nRow; },what i am trying to achieve is reversing the priority got from the server data (6 high priority - 0 low priority) for the purposes of sorting by priority so ascending (0 high - 6 low).many Thanks for your help
Shibbott
After the fnRowCallback I do this sorting to try and sort by the revised Best Match (priority) "aaSorting": [[ 2, "asc" ]], "aoColumns": [ /*checkbox*/{ "bSortable": false }, /*ID*/{"bVisible": false }, /*best match*/null, /*VenueName*/null, /*Distance*/null, /*Capacity*/null, /*MeetingRooms*/null, /*Bedrooms*/null, /*Suitability*/null ]});
Shibbott
A: 

You need to update the datatable, not html.

oTable.fnUpdate( newValue, rowPos, columnPos);

assuming oTable is a reference to the datatable. See datatable docs for how to edit a row.

Yisroel
Thanks I'll give it ago, I guess i need jeditable ti use fnUpdate, yeah?
Shibbott
you should not need to use jEditable, just use fnUpdate. jEditable itself is not doing anything special other than calling fnUpdate in the example.
Yisroel