Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81926

custom sorting column on the basis of priority for datatable

$
0
0

I want to custom sort data Table on the basis of priority. I have written code as follows. can anyone help me with please. I saw some solution here in this forum. My problem is: its not sorting properly. I want to sort forth column on the basis of priority but it is not working as expected.

here is my code

$(document).ready(function() {
$('#dashboard').DataTable({
"lengthMenu" : [ [ 25, 50, 75, -1 ], [ 25, 50, 75, "All" ] ],
"pageLength" : 200,
"aoColumns" : [ null, null, null, {
"sType" : "priority",
"bSortable" : true
} ]
});
});

function getPriority(name) {

var rankNumber;

if (name == "High - 1st") {
    rankNumber = 1;
} else if (name == "High - 2nd") {
    rankNumber = 2;
} else if (name == "High - 3rd") {
    rankNumber = 3;
} else if (name == "High - 4th") {
    rankNumber = 4;
} else if (name == "High - 5th") {
    rankNumber = 5;
} else if (name == "High") {
    rankNumber = 6;
} else if (name == "Medium") {
    rankNumber = 7;
} else if (name == "Low") {
    rankNumber = 8;
} else if(name == "") {
    rankNumber = 9;
}

return rankNumber;

}

jQuery.fn.dataTableExt.oSort["priority-desc"] = function(x, y) {
    return getPriority(x) < getPriority(y);
};

jQuery.fn.dataTableExt.oSort["priority-asc"] = function(x, y) {
    return getPriority(x) > getPriority(y);
}

I have attached my screen shot of table. Forth column(i.e Requested Priority) is sorting randomly(expected to sort on the basis of rankNumber but not working) Can anyone help me with this.

Thank you in advance!


Viewing all articles
Browse latest Browse all 81926

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>