(v1.9.4) This solution not only fixes your sorting problems, but also eliminates filtering problems, because the filter usually matches HTML, so searching for things like href or div matches all the lines.
It removes the HTML inside the mRender option, and then caches the result, since DataTables runs the mRender function several times.
JsFiddle example
Warning for editable tables
An editable table may have problems due to the caching mechanism.
Step1
Include the following javascript somewhere:
var stripHtml = (function() { var tmpDiv = document.createElement("DIV"); return function(html) { tmpDiv.innerHTML = html; return $.trim(tmpDiv.textContent || tmpDiv.innerText); }; })(); var mRenderFactory = function (colIndex) { return function (data, type, full) { var cache = MRenderCache.getCache(full); if (type === "filter" || type === "sort" || type === "type") { return cache.getOrElse(colIndex, data, stripHtml) } return data; }; }; var MRenderCache = function () { this.full = []; } MRenderCache.getCache = function (full) { var cache = full[full.length - 1]; if (cache == null || !cache.MRenderCache) { cache = new MRenderCache(); full.push(cache); } return cache; } MRenderCache.prototype.MRenderCache = true; MRenderCache.prototype.getOrElse = function (colIndex, rawData, convert) { var result = this.full[colIndex]; if (result === undefined) { result = convert(rawData); this.full[colIndex] = result; } return result; }
Step 2
Set "mRender": mRenderFactory(i) inside aoColumns in any columns that you want HTML to split, where i is the column index. It is VERY important that you get the correct i , because if you do not, the table will be displayed in order, but it will sort and filter the wrong column.
The initialization code will look something like this:
$(document).ready(function() { $('#example').dataTable( { "aoColumns": [ null, null, { "mRender": mRenderFactory(2) }, { "mRender": mRenderFactory(3) }, null ] } ); } );