Sorting doesn't work after changing the text of a TD tag using JQuery

Sorting doesn't work after changing the text of a TD tag using JQuery

wingchanwingchan Posts: 2Questions: 0Answers: 0
edited October 2011 in General
Hi,
I use JQuery to set a click event handler on the link C3. The handler just change the text C3 to Changed. Then the sorting doesn't work. Any way to fix the sorting? Thanks.
Wing

Below is my code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">






$(document).ready(function() {
$('#3').bind('click',function () {
$('#3').text("Changed");
});

$('#example').dataTable();
} );






ID
A
B
C




1
A1
B1
C1


2
A2
B2
C2


3
A3
B3
C3


4
A4
B4
C4

Replies

  • allanallan Posts: 64,506Questions: 1Answers: 10,660 Site admin
    You need to use fnUpdate ( http://datatables.net/api#fnUpdate ) to update cell contents rather than manipulating them directly. This allows DataTables to know that you've made the change to the cell.

    Allan
  • wingchanwingchan Posts: 2Questions: 0Answers: 0
    Hi Allan,
    I am using the paging feature. If the fnUpdate is called in a second page, the whole table will go back to the first page. Any way to stay in the second page instead of going back to the first page?
    Thanks a lot.
    Wing
  • allanallan Posts: 64,506Questions: 1Answers: 10,660 Site admin
    Pass in 'false' as the forth parameter to fnUpdate to stop it from doing a redraw. The reason it jumps back is that the table does a full redraw (i.e. sorting, filtering etc) to take account of the new data, since it might have changed the position of the row.

    There is also the standing redraw plug-in which you can use if you do want the sorting / filtering to be updated (again pass in false as above to fnUpdate), but have the table do a redraw on the current page: http://datatables.net/plug-ins/api#fnStandingRedraw

    Allan
This discussion has been closed.