Why is my tablesorter caching my old rows?

I use tablesorter to sort the grid on one of my pages. I make an AJAX call every 10 seconds to update the stock information and update my grid accordingly. This works a lot, but I can’t set the sorting options correctly. Rather, I seem to have cached sorting, but when I do this, tablesorter also caches my previous rows and displays them along with a new, sorted rowset.

For example, my initial grid has 10 rows of data. I sort the second column. After 10 seconds, a new set of 10 lines appears, but my initial 10 lines still appear, although I freed them. I have researched everything and I cannot find an answer for this.

If I don't sort at all, and I don't call the trigger for "sorton", I get 10 rows as desired, but the rows are not sorted, of course. If I call this trigger for "sorton", my data is sorted, but I get 10 new lines each time the function is called (20 lines, 30 rows, etc.).

Here is my code from my AJAX call:

if (myResult.Data.length > 0) {
    $.each(myResult.Data, function() {
        myRows += "<tr><td>" + this.column1 + "</td><td>" + this.column2 + "</td></tr>";
    });
    $("#myTBody").empty();
    //    $("#myTBody").append(myRows);    //tried this first
    //    $("#myTable").trigger("update"); // combined with this
    $("#myTBody").append(myRrows).trigger("update");
    var sorting = $("#myTable")[0].config.sortList;
    $("#myTable").trigger("sorton", [sorting]);
}
+5
source share
3 answers

Hmm, this seems like a problem with the original table browser ( demo ).

Sorry, I don’t remember why the cache is not cleared during the update; but this problem does not occur in my fork tablesorter ( demo ).

+3
source

, , - , tablesorter, , sorton "".

$("#myTBody").append(myRrows).trigger("update");
var sorting = $("#myTable")[0].config.sortList;
setTimeout(function () {
    $("#myTable").trigger("sorton", [sorting]);
}, 100);

, update . 1 update. , sorton . , JS, , , .

: http://jsfiddle.net/eY8uH/692/

+7

:

$("#myTBody")
  .append(myRrows);
$("#myTable")
  .trigger("update")
  .trigger("sorton", [$("#myTable")[0].config.sortList])
  .trigger("appendCache");

: fooobar.com/questions/281876/...

0

All Articles