vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
732 stars 284 forks source link

sortColumnData workaround for ukrainian locale #538

Closed dabeedj closed 5 years ago

dabeedj commented 5 years ago

Hello I use version 0.9.3 Had to change your code a bit:

                if (columnObj.sort_as === "alpha") {
                    if (columnObj.sort_order === "asc") {
                        column_data.sort(sortAlpha);
                    } else if (columnObj.sort_order === "desc") {
                        column_data.sort(sortAlpha);
                        column_data.reverse();
                    }
                }

and add sortAlpha function

        function sortAlpha(a, b) {
            if (typeof a.label !== 'undefined' && typeof b.label !== 'undefined') {
                if (typeof a.label[0] !== 'undefined' && typeof b.label[0] !== 'undefined') {
                    return a.label[0].localeCompare(b.label[0], 'uk');
                } else {
                    return 0;
                }
            } else if (typeof a !== 'undefined' && typeof b !== 'undefined') {
                return a.localeCompare(b, 'uk');
            } else {
                return 0;
            }
        }

So ukrainian words are sorted correctly Will appreciate to have some kind of workaround for locales in future updates

vedmack commented 5 years ago

You can use the [sort_as_custom_func] , just set the sort_as: 'custom' and provide sort_as_custom_func with your own sorting fucntion

(https://github.com/vedmack/yadcf/blob/5ab21cd7ca91ce36ec21b0caf108d9198b19af94/src/jquery.dataTables.yadcf.js#L158)

  • sort_as_custom_func Required: false Type: function Default value: undefined Description: Allows to provide a custom sorting function for the filter elements
dabeedj commented 5 years ago

Thanks