Question

I have a datatable, where I already made dropdowns for filtering my lines. My problem is that the values in the drop down itself aren't sorted...

Here is my code:

this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i), $("#" + i).val());
$('select', this).change(function () {
    var searchVal = $(this).val().replace(/\&/g, '&');
    if (searchVal != '') {
        searchVal = '^' + searchVal + '$';
    }
    oTable.fnFilter(searchVal, i, true, false);
});

Thanks!

Was it helpful?

Solution

Ok, found the answer:

all that was needed to be done is to write oTable.fnGetColumnData(i).sort() instead of oTable.fnGetColumnData(i). Then I also wanted the sorting not to be case sensitive, so I changed it again to:

oTable.fnGetColumnData(i).sort(function(a, b) {
    if (a.toLowerCase() < b.toLowerCase()) return -1;
    if (a.toLowerCase() > b.toLowerCase()) return 1;
    return 0;
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top