Create a gist now

Instantly share code, notes, and snippets.

Embed
DataTables plug-in for displaying sort priorities in each sorted column header
$('#example').dataTable().fnSortPriorities();
$.fn.dataTableExt.oApi.fnSortPriorities = function(oSettings) {
var $this = $(this);
$this.find('> thead tr th').each(function(i, v) {
v.innerHTML += '<div class="dataTable-sort-priority"></div>';
});
function checkSort(sorts) {
var $priorities = $this.find('> thead tr th div.dataTable-sort-priority');
$priorities.html('');
if (sorts && sorts.length > 1) {
for (var i=0,len=sorts.length; i<len; ++i)
$priorities[sorts[i][0]].innerHTML = (i + 1);
}
}
$this.on('sort', function(ev, oSettings) {
checkSort(oSettings.aaSorting);
});
// Check for initial multisort
checkSort(oSettings.aaSorting);
};
table thead tr th div.dataTable-sort-priority {
float: right;
font-size: 9px;
padding-right: 5px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment