TL;DR: How can I prevent tablesorter from caching data when a new ajax call is made? Or how can I clear tablesorter's cache when a call is made?
I am sorting a table populated with data from an ajax request. Depending on where I initialize tablesorter, I run into one of two problems:
1 - If I initialize based off the click event that fires the ajax and then trigger a sort in the success function, it doesn't sort on the initial data, a header has to be clicked to initiate the sort.
Example:
event to fire off ajax call:
$('#id_department'
).change(
function
()
{
timer && clearTimeout(timer);
timer = setTimeout(create_post, 300);
$('#results').empty();
$("#results_table").tablesorter({debug: true } );
});
on success:
var sorting =
[[0,0
]
];
$("#results_table").trigger("sorton",[sorting]);
2 - If I initialize the sort in the ajax success function rather than before the ajax call, the initial sort is correct, but if I fire another ajax event, which clears the table and repopulates it, tablesorter keeps the cached data from the previous call and ends up doubling up a lot of the data.
Example:
ajax success:
...
$(
"#results_table").tablesorter(
{debug:
true
} );
var sorting =
[[0,0
],
];
$(
"#results_table").trigger(
"sorton",
[sorting
]);
How can I prevent tablesorter from caching data when a new ajax call is made? Or how can I clear tablesorter's cache when a call is made?