Wrong Sorting after Changing Value in SelectBox

Wrong Sorting after Changing Value in SelectBox

MalikoMaliko Posts: 1Questions: 1Answers: 0
edited August 2016 in Free community support

Hey,

i've a little Problem with the sorting-function of the DataTables-Plugin. I've written an own sorting-Function for a column there get the Values from SelectBoxes. But when i change a value and want to sort the Column than they used the old values .

e.g. the values are 5,3,1,2,4,6 and i change 1 to 2 and 2 to 1 than the order after sorting is 2,1,3,4,5,6. Has anyone an Idea what i can do? I'm using the following code:

$('#table').DataTable({
responsive: false,
iDisplayLength: 25,
sScrollX: "100%",
sScrollXInner: "100%",
bFilter: false,
info: false,
bPaginate: false,
searchHighlight: false,
sDom: 'fliprtip',
order: [],
columnDefs: [
{ type: 'own-select', targets: [5] }
]
});

and this is the sorting algorithim:

`jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"own-select-asc": function (a, b) {
var sAValue = $(a).find('option:selected').val();
var sBValue = $(b).find('option:selected').val();

    if(!isNaN(sAValue) && isNaN(sBValue)) {
        return -1;
    } else if(isNaN(sAValue) && !isNaN(sBValue)) {
        return 1;
    } else if(!isNaN(sAValue) && !isNaN(sBValue)) {
        if(parseInt(sAValue) < parseInt(sBValue)) {
            return -1;
        } else if (parseInt(sAValue) > parseInt(sBValue)) {
            return 1;
        } else {
            return 0;
        }
    } else if(isNaN(sAValue) && isNaN(sBValue)) {
        if(sAValue < sBValue) {
            return -1;
        } else if(sAValue > sBValue) {
            return 1;
        } else {
            return 0;
        }
    }
},

"own-select-desc": function (a, b) {
    var sAValue = $(a).find('option:selected').val();
    var sBValue = $(b).find('option:selected').val();

    if(!isNaN(sAValue) && isNaN(sBValue)) {
        return 1;
    } else if(isNaN(sAValue) && !isNaN(sBValue)) {
        return -1;
    } else if(!isNaN(sAValue) && !isNaN(sBValue)) {
        if(parseInt(sAValue) < parseInt(sBValue)) {
            return 1;
        } else if (parseInt(sAValue) > parseInt(sBValue)) {
            return -1;
        } else {
            return 0;
        }
    } else if(isNaN(sAValue) && isNaN(sBValue)) {
        if(sAValue < sBValue) {
            return 1;
        } else if(sAValue > sBValue) {
            return -1;
        } else {
            return 0;
        }
    }
}

} );`

The SortingFunction itself is working fine. Thanks a lot.

Yours Sincerly
Maliko

This discussion has been closed.