Sort Account-Level Course Page Terms in Descending Order

dgrobani
Community Champion
21
4342

The terms list on the account-level course page is sorted in ascending order. When I filter terms, I almost always want the current term or a recent term. Having to scroll to the bottom of our long list of terms is annoying, so I wrote some JavaScript (with the help of Stack Overflow) to sort the list by term ID in descending order. In case anyone else might find this useful, here it is:

if (window.location.pathname.indexOf('accounts') > -1) {
    // https://stackoverflow.com/questions/20693593
    var selectOptions = $('select optgroup[label="Active Terms"] option');
    selectOptions.sort(function(a,b){
        return parseInt(b.value) > parseInt(a.value);
    });
    $('select optgroup[label="Active Terms"]').html(selectOptions);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

(I welcome tips for improvement, carroll-ccsd  @James ‌!)

Tags (2)
21 Comments