Implementacja niestandardowej funkcji sSortType i sortowania dla tabel danych jQuery

Trudno mi jest postępować zgodnie z instrukcjami na stroniedokumentacja strona. Mam tabelę wyświetlającą średni czas trwania w jednej kolumnie, w formacie HH: MM, np. 10:45 oznacza dziesięć godzin i czterdzieści pięć minut. Chciałbym móc sortować całą tabelę według wartości w tej kolumnie.

Oto mój kod inicjujący:

    var aoTable = $("#TableStatistic").dataTable({
    "bDestroy": true,
    "sDom": "<'row-fluid dt-header'<'span6'f><'span6'T>>t<'row-fluid dt-footer'<'span6'i><'span6'p>>",
    "oTableTools": {
        "aButtons": ["xls", "pdf", "print"],
        "sSwfPath": "../Content/media/swf/copy_csv_xls_pdf.swf"
    },
    "aaData": statisticsModel.byCategoriesList(),
    "aaSorting": [[0, "desc"]],
    "bPaginate": false,
    "aoColumns": [
        { "mDataProp": "CategoryName", "sTitle": "Reports.CategoryName" },
        { "mDataProp": "AverageTime", "sTitle": "Reports.AverageTime", "sSortDataType": "duration-desc"},
        { "mDataProp": "NumberOfProblemsSolved", "sTitle": "Reports.NumberOfProblemsSolved" }
    ],
    "oLanguage": MeridianTranslation.DataTable

});

Oto coZAKŁADAM być właściwym sposobem dodania nowej funkcji sortowania i nowego typu sSortType do mojej tabeli:

jQuery.extend(jQuery.fn.dataTableExt.oSort['duration-desc'] = function (x, y) {
    var xHours = parseInt(x.slice(0, x.indexOf(':')));
    var xMinutes = parseInt(x.slice(x.indexOf(':') + 1, x.length)) + xHours * 60;
    var yHours = parseInt(y.slice(0, y.indexOf(':')));
    var yMinutes = parseInt(y.slice(y.indexOf(':') + 1, y.length)) + yHours * 60;
    return ((xMinutes < yMinutes) ? -1 : ((xMinutes > yMinutes) ? 1 : 0));
});

jQuery.extend(jQuery.fn.dataTableExt.oSort['duration-asc'] = function (x, y) {
    var xHours = parseInt(x.slice(0, x.indexOf(':')));
    var xMinutes = parseInt(x.slice(x.indexOf(':')+1, x.length)) + xHours * 60;
    var yHours = parseInt(y.slice(0, y.indexOf(':')));
    var yMinutes = parseInt(y.slice(y.indexOf(':')+1, y.length)) + yHours * 60;
    return ((xMinutes < yMinutes) ? 1 : ((xMinutes > yMinutes) ? -1 : 0));
});

Przypuszczam, że istnieje o wiele lepszy sposób na wyodrębnienie liczby minut niż sposób, w jaki to robię, ale załóżmy, że mój algorytm jest prawidłowy. Co muszę zrobić, aby poprawnie zainicjować tabelę danych i zintegrować z nią tę funkcję sortowania i typ danych? Sama tabela renderuje się poprawnie, ale gdy próbuję posortować kolumnę, sortuje się leksykograficznie, jakby to był łańcuch. Jakieś pomysły?

questionAnswers(2)

yourAnswerToTheQuestion