jQuery dataTable custom sort picking up OLD HTML?
I have this custom sorter on a dataTable:
jQuery.fn.dataTableExt.oSort['abbr-date-asc'] = function(a,b) {
var x = a.match(/abbr="(.*?)"/)[1];
var y = b.match(/abbr="(.*?)"/)[1];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
When I enter the debugger what is in the A variable is OLD HTML, i.e what is there when the page is first drawn. After the page is drawn and in the onReady function before this code ^^ is executed I redraw the TDS in my table to be different HTML that I want this custom sorter to pick up. It is picking up the old stuff. Any idea?
EDIT: HERE IS THE HTML
<span abbr="">
<span class="localtimeUTC" style="display: none;">Dec 03, 2011</span>
<span class="localtimeUTCabbr" style="display: none;">2011-12-03</span>
</span>
And this is the HTML on the page at the time of click when I want to sort it:
<span abbr="2011-12-03">Dec 03, 2011</span>
It is picking up the original. I have tried using 开发者_如何学PythonbUseRendered: false in the table definition, no dice. I tried converting the sort function to a closure, no dice.
jQuery('#my_table').dataTable( {
"bJQueryUI": true,
"bAutoWidth": false,
"bUseRendered" : false,
"aoColumns" : [
{ sWidth: '5%', bSortable: false, bSearchable: false },
{ sWidth: '35%' },
{ sWidth: '15%' },
{ sWidth: '15%', sType: 'abbr-date', bSortDataType: "abbr-date" },
{ sWidth: '30%', bSortable: false, bSearchable: false }
],
}).show();
OK I found the answer: I was not using DataTable properly. I was re-rendering TDs using my own JS outside of the DataTable but using a combination of
fnRender bUseRendered: false Firebug
I was able to have the current, proper HTML returned. It turns out that DataTable keeps a cache of the original table by default and by using these two things I was able to get current HTML.
精彩评论