SOURCE

function regionSort(d1, d2) {

    var ts1 = d1['rjrgts'];
    var ts2 = d2['rjrgts'];

    ts1 = ts1 == '-' ? -Infinity : Number(ts1);
    ts2 = ts2 == '-' ? -Infinity : Number(ts2);

    return ts2 - ts1;
}

function rjrgtsSortAsc(d1, d2) {

    var ts1 = d1['rjrgts'];
    var ts2 = d2['rjrgts'];

    ts1 = ts1 == '-' ? -Infinity : Number(ts1);
    ts2 = ts2 == '-' ? -Infinity : Number(ts2);

    return ts1 - ts2;
}

function rjrgjeSortAsc(d1, d2) {

    var je1 = d1['rjrgje'];
    var je2 = d2['rjrgje'];

    je1 = je1 == '-' ? -Infinity : Number(je1);
    je2 = je2 == '-' ? -Infinity : Number(je2);

    return je1 - je2;
}

function rjrgjeSortDesc(d1, d2) {

    var je1 = d1['rjrgje'];
    var je2 = d2['rjrgje'];

    je1 = je1 == '-' ? -Infinity : Number(je1);
    je2 = je2 == '-' ? -Infinity : Number(je2);

    return je2 - je1;
}

function rjjdzsSortAsc(d1, d2) {

    var zs1 = d1['rjjdzs'];
    var zs2 = d2['rjjdzs'];

    zs1 = zs1 == '-' ? -Infinity : Number(zs1);
    zs2 = zs2 == '-' ? -Infinity : Number(zs2);

    return zs1 - zs2;
}

function rjjdzsSortDesc(d1, d2) {

    var zs1 = d1['rjjdzs'];
    var zs2 = d2['rjjdzs'];

    zs1 = zs1 == '-' ? -Infinity : Number(zs1);
    zs2 = zs2 == '-' ? -Infinity : Number(zs2);

    return zs2 - zs1;
}

function dfzrglSortAsc(d1, d2) {

    var rgl1 = d1['dfzrgl'];
    var rgl2 = d2['dfzrgl'];

    rgl1 = rgl1 == '-' ? -Infinity : Number(rgl1);
    rgl2 = rgl2 == '-' ? -Infinity : Number(rgl2);

    return rgl1 - rgl2;
}

function dfzrglSortDesc(d1, d2) {

    var rgl1 = d1['dfzrgl'];
    var rgl2 = d2['dfzrgl'];

    rgl1 = rgl1 == '-' ? -Infinity : Number(rgl1);
    rgl2 = rgl2 == '-' ? -Infinity : Number(rgl2);

    return rgl2 - rgl1;
}

function processData(columnStr, dataStr, paramStr) {
    var datas = JSON.parse(dataStr);
    var queryParams = JSON.parse(paramStr);
    var orders = JSON.stringify(queryParams['orders']);

    var order;
    if (orders != undefined) {
        orders = JSON.parse(orders);
        order = orders.length > 0 ? JSON.parse(JSON.stringify(orders[0])) : undefined;
    }

    if (order === undefined || (order['direction'] != 'asc' && order['direction'] != 'desc')) {
        datas.sort(regionSort);
    }

    if (order != undefined) {

        var column = order['column'];

        switch (column) {
            case '`rjrgje`':

                if (order['direction'] == 'asc') {
                    datas.sort(rjrgjeSortAsc);
                }

                if (order['direction'] == 'desc') {
                    datas.sort(rjrgjeSortDesc);
                }

                break;
            case '`rjjdzs`':

                if (order['direction'] == 'asc') {
                    datas.sort(rjjdzsSortAsc);
                }

                if (order['direction'] == 'desc') {
                    datas.sort(rjjdzsSortDesc);
                }

                break;
            case '`dfzrgl`':

                if (order['direction'] == 'asc') {
                    datas.sort(dfzrglSortAsc);
                }

                if (order['direction'] == 'desc') {
                    datas.sort(dfzrglSortDesc);
                }

                break;
            case '`rjrgts`':

                if (order['direction'] == 'asc') {
                    datas.sort(rjrgtsSortAsc);
                }

                if (order['direction'] == 'desc') {
                    datas.sort(regionSort);
                }

                break;
            default:
                break;
        }
    }

    var index = -1;
    var indexs = [];
    for (var i = 0; i < datas.length; i++) {
        var d = datas[i];
        // 一个地区或者事业部,只有一个尾盘合计
        if (d['project_name'] == '尾盘合计') {
            index = i;
        }

        var wp = d['is_wp'];
        if (wp == '是' && d['project_name'] != '尾盘合计') {
            indexs.push(i);
        }
    }

    // 存在尾盘将尾盘合计置底
    if (datas.length > 0 && index > -1) {
        var d = datas[index];
        datas.splice(datas.length, 0, d);
        datas.splice(index, 1);
    }

    for (var i = 0; i < indexs.length; i++) {
        datas.splice(indexs[i], 1);
    }

    return JSON.stringify(datas);
}
console 命令行工具 X clear

                    
>
console