jQuery find() works in IE, but not Chrome or Firefox
I'm s开发者_Go百科etting up custom textExtraction for the jQuery plugin tablesorter control (which is probably irrelevant) and the sort works in IE, but not Chrome or Firefox. Here's a snippet of the JavaScript code:
var searchResultsTables = $("table.FilterClass");
searchResultsTables.tablesorter({
widgets: ['zebra'],
widgetZebra: { css: ["Odd", "Even"] },
headers:
{
3: { textExtraction: function (node)
{
return $(node).find("img").length;
}
},
4: { sorter: false }
}
}
);
Node is the <td>
(I believe). Some cells have an image in them and others don't. So, basically, this column should sort based on 0/1. All the other columns sort just fine (with the exception of the 5th column, which, as you can see, is set not to be sortable).
Here is a bit of the html upon which the sort is acting (2 rows):
<table class="SearchResultsTable FilterClass tablesorter">
<tr class="Odd">
<td class="SearchResultsCell RightBrownBorder NameCell">
<a href="/Candidate/2">Bill Clinton</a></td>
<td class="SearchResultsCell RightBrownBorder PartyCell">Democrat</td>
<td class="SearchResultsCell RightBrownBorder DistrictCell"></td>
<td class="SearchResultsCell RightBrownBorder IncumbentCell">
<img src="/Images/green_check_mark.gif" />
</td>
<td class="SearchResultsCell PoliticalSpectrumIndexCell"></td>
</tr>
<tr class="Even">
<td class="SearchResultsCell RightBrownBorder NameCell">
<a href="/Candidate/13">Newt Gingrich</a></td>
<td class="SearchResultsCell RightBrownBorder PartyCell" title="Party for Socialism and Liberation">Party for...</td>
<td class="SearchResultsCell RightBrownBorder DistrictCell"></td>
<td class="SearchResultsCell RightBrownBorder IncumbentCell"></td>
<td class="SearchResultsCell PoliticalSpectrumIndexCell"></td>
</tr>
Any ideas why this wouldn't work in Chrome or Firefox?
I don't think you can put a textextraction function within the header option.
When I coded an example like yours, I had this, and it worked:
var searchResultsTables = $("table.FilterClass");
searchResultsTables.tablesorter({
widgets: ['zebra'],
widgetZebra: { css: ["Odd", "Even"] },
textExtraction: function (node)
{
if (node.cellIndex == 3)
{
return $(node).find("img").length;
}
else
{
return node.innerHTML
}
}
headers:
{
4: { sorter: false }
}
} );
精彩评论