Skip to content

Instantly share code, notes, and snippets.

@cmurtaugh cmurtaugh/sort_terms.js
Last active Jul 6, 2016

Embed
What would you like to do?
Custom javascript to sort terms in Canvas
function sortTermDropdown(){
var termSelect = $('select[name="enrollment_term_id"]');
var selectedOption = $(termSelect).val();
var termSelectList = $('option', termSelect);
var newList = termSelectList.sort(function(a,b){
return (a.label >= b.label) ? -1 : 1;
});
$(termSelect).html(newList).val(selectedOption);
};
function sortTermTable(){
var termRowList = $('table#terms tbody tr.term').get();
var newList = termRowList.sort(function(a,b){
var alabel = a.getElementsByClassName('name')[0].innerHTML;
var blabel = b.getElementsByClassName('name')[0].innerHTML;
return (alabel >= blabel) ? -1 : 1;
});
$('table#terms').children('tbody').append(newList);
};
$(document).ready(function() {
if ($('select[name="enrollment_term_id"]').length > 0) {
sortTermDropdown();
}
if ($('table#terms').length > 0) {
sortTermTable();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.