How add dynamic List in switch case in js?I have used this in custom sorting datatable jquery plugin.
I have added static code in switch case its working. but its not in Dynamic list.
Static Switch code:
*jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"enums-pre": function ( a ) {
// Add / alter the switch statement below to match your enum list
switch( a ) {
case "Target": return 1;
case "Qualify": return 2;
case "Discover": return 3;
case "Verify": return 4;
case "Present": return 5;
case "Closed Won": return 6;
case "Closed Lost": return 7;
case "Manage": return 8;
case "Sales Plan": return 9;
default: return 10;
}
},
Dynamic Switch code:
oppStage is a json string
$(document).ready(function() {
var oppStage = '["Target","Qualify","Discover","Verify","Present","Closed Won","Closed Lost","Manage","Sales Plan","Actual Sales LY"]';
var oppList = jQuery.parseJSON(oppStage);
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"enums-pre": function ( a ) {
// Add / alter the switch statement below to match your enum list
var i =0;
for(;i<oppList.length;i++){
console.log(oppList[i]+oppList.length);
switch( a ) {
case "+oppList[i]+": return i;
}
}
},
"enums-asc": function ( a, b ) {
console.log(':::second:::'+a);
console.log(':::third:::'+b);
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"enums-desc": function ( a, b ) {
console.log(':::fourth:::'+a);
console.log(':::fifth:::'+b);
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
$('.oppCls1').dataTable( {
"aoColumnDefs": [
{ "sType": "enums", "aTargets": [2]}
]
});
});
How to resolve this for dynamic array code?