Problem with sorting after updating a cell using jQuery's .html()

Problem with sorting after updating a cell using jQuery's .html()

rasmuslindstromrasmuslindstrom Posts: 7Questions: 0Answers: 0
edited September 2012 in General
Hello!

I have a table where one column is just numbers. If I change a number using jQuery's .html like this: $('#price_123').html(5);

The sorting still treats this '5' like the old value when sorting.

I can't find any information on this, I'm hoping that I just could run like $('#example').dataTable().fnUpdate(); or something =)


Big thanks in advance!

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Don't use $().html() use the API, specifically fnUpdate in this case. See http://datatables.net/faqs#append for more information.

    Allan
  • rasmuslindstromrasmuslindstrom Posts: 7Questions: 0Answers: 0
    Thanks for a Quick reply!

    I have a which loads a file, which has a script that loops 20 times and each time, it adds a row and does a bunch of other stuff. When using the .html() to update a cell I get 20 new rows and everything is working (except the datatables sorting).

    When I changed method, to fnUpdate I only get 8 rows (although sorting works now). If I click on the again, in the first example, I get 20 new rows, in this one, I don't get any rows the second time.


    Here's the code that replaces the jQuery .html():
    (flight_123_126 is the id of the parent TR)

    var pos = $('#example').dataTable().fnGetPosition((flight_123_126));
    $('#example').dataTable().fnUpdate('533', pos, 3);


    I can't figure out what's the problem, do I need to use "return false;" or something, or is my code not correct?


    Thanks in advance!
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    I don't quite understand how the 20 rows with html() relates to the 8 rows with fnUpdate() I'm afraid. fnUpdate can't be used to add rows, you need to use fnAddData for that. How are you currently adding rows to the table? Perhaps you can give us a link so we can see what is going on?

    Thanks,
    Allan
This discussion has been closed.