fooplugins / FooTable

jQuery plugin to make HTML tables responsive
https://fooplugins.com/plugins/footable-jquery/
Other
2.13k stars 637 forks source link

How to Sort Chinese by Initials #760

Open Deft-pawN opened 6 years ago

Deft-pawN commented 6 years ago

I am new User of Footable, Can I sort the Chinese by Initials? Can anyone help me? Thanks in advance~

Deft-pawN commented 6 years ago

I have solved the problem,You can change the footable.js on line 2157

    F.Column.prototype.sorter = function(a, b,c,d){
        if (c == 'DESC') {
            if (typeof a === 'string') a = a.toLowerCase().trim();
            if (typeof b === 'string') b = b.toLowerCase().trim();
            if (a == undefined && b == undefined) return 0;

            if (a == undefined || a == "") {
                return -1;
            }
            if (b == undefined || b == "") 
            {   
                return 1;
            }
            if(d == 'number') {
                if (a < b) return -1;
                return 1;
            }
            return a.localeCompare(b,'zh');         
        } else {
            if (typeof a === 'string') a = a.toLowerCase().trim();
            if (typeof b === 'string') b = b.toLowerCase().trim();
            if (a == undefined && b == undefined) {
                return 0;
            }
            if (a == undefined || a == "") {
                return 1;
            }
            if (b == undefined || b == "") 
            {   
                return -1;
            }
            if (a === b) {
                return 0;
            }
            if(d == 'number') {
                if (a < b) return -1;
                return 1;
            }
            return a.localeCompare(b,'zh');             
        }
    };

line 4905

predraw: function () {
            if (!this.column) return;
            var self = this, col = self.column;
            self.ft.rows.array.sort(function (a, b) {
                return col.direction == 'DESC'
                        ? col.sorter(b.cells[col.index].sortValue, a.cells[col.index].sortValue,col.direction,col.type)
                        : col.sorter(a.cells[col.index].sortValue, b.cells[col.index].sortValue,col.direction,col.type);
            });
        },