Skip to content

Instantly share code, notes, and snippets.

@mscdex
Created May 16, 2013 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mscdex/5594752 to your computer and use it in GitHub Desktop.
Save mscdex/5594752 to your computer and use it in GitHub Desktop.
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