2

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!

1 Answer 1

2

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;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.