Failing to implement enum style plug-in sorting
Failing to implement enum style plug-in sorting
estearns
Posts: 2Questions: 0Answers: 0
Been fighting at this for a while today, not sure what is wrong. To preface everything, I'm *not* a seasoned javascript/jQuery programmer. I've used datatables once before, successfully, and done a few small projects as well. I could be overlooking something very simple. My company has a project management system that displays a table of assignments with varying status'. Right now there is no way to sort this table, and I'm trying to get datatables to work. Most important to my coworkers is to have it sortable by status, and so I've tried to make a custom function to do this.
[code]jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"status-enum-pre": function ( a ) {
switch(a) {
case "New": return 1;
case "Assigned": return 2;
case "In Progress": return 3;
case "Resolved": return 4;
case "Task": return 5;
case "Feedback - Internal": return 6;
default: return 7;
}
},
"status-enum-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"status-enum-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
},
});
$(document).ready(function() {
jQuery('#example').dataTable( {
"iDisplayLength": -1,
"aoColumns": [
null,
null,
null,
null,
{ "sType": "status-enum" },
null,
null,
],
} );
} );
[/code]
I have tested a lot of different variations of this code without any luck. There are 7 columns being displayed. The 7 with default settings work as expected. The 5th column, Status, has no functionality in respect to sorting. I don't really know what else to elaborate on, so questions in respect to this are more than welcome. Thanks in advance.
Eric
[code]jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"status-enum-pre": function ( a ) {
switch(a) {
case "New": return 1;
case "Assigned": return 2;
case "In Progress": return 3;
case "Resolved": return 4;
case "Task": return 5;
case "Feedback - Internal": return 6;
default: return 7;
}
},
"status-enum-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"status-enum-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
},
});
$(document).ready(function() {
jQuery('#example').dataTable( {
"iDisplayLength": -1,
"aoColumns": [
null,
null,
null,
null,
{ "sType": "status-enum" },
null,
null,
],
} );
} );
[/code]
I have tested a lot of different variations of this code without any luck. There are 7 columns being displayed. The 7 with default settings work as expected. The 5th column, Status, has no functionality in respect to sorting. I don't really know what else to elaborate on, so questions in respect to this are more than welcome. Thanks in advance.
Eric
This discussion has been closed.
Replies