creating custom ordering
creating custom ordering
Hello all!
I want to be able to manipulate my statuses(column), when I go to sort the list comes up alphnumeric. Status I have:
Active
Inactive
Part-Time
I would like to have the statuses sort to:
Active
Part-Time
Inactive
I could just add space to the active and Inactive and that would sort correctly. Would much rather do a correct ordering through the data tables script.
Thanks in advance.
D
I want to be able to manipulate my statuses(column), when I go to sort the list comes up alphnumeric. Status I have:
Active
Inactive
Part-Time
I would like to have the statuses sort to:
Active
Part-Time
Inactive
I could just add space to the active and Inactive and that would sort correctly. Would much rather do a correct ordering through the data tables script.
Thanks in advance.
D
This discussion has been closed.
Replies
And while sorting you can give weight to each status and sort according to that weight.
Anjib
This makes sense but none of the values in each of those links talks about weighted values.
What i would like to do is create a custom ordering to make my statuses line up right for my end users.
Order:
Active
Part-Time
Inactive
instead of alpha numeric:
Active
Inactive
Part-Time
Is there a coding example on how to weight the values?
Thanks
Doug
Allan
[code]
$(document).ready( function () {
fnPriority( a )
{
if ( a == "Active" ) { return 1; }
else if ( a == "Part-Time" ) { return 2; }
else if ( a == "Inactive" ) { return 3; }
return 4;
}
jQuery.fn.dataTableExt.oSort['priority-asc'] = function(a,b) {
var x = fnPriority( a );
var y = fnPriority( b );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['priority-desc'] = function(a,b) {
var x = fnPriority( a );
var y = fnPriority( b );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
TableToolsInit.sSwfPath = "../inc/datatables/media/swf/ZeroClipboard.swf";
var oTable = $('#example2').dataTable( {
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"iDisplayLength": 100
} );;
} );
[/code]
[code]
var oTable = $('#example2').dataTable( {
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"iDisplayLength": 100,
"aoColumns": [
{ "sType": "priority" }, //Status column
........................ //your other columns
]
} );
[/code]
Correct me Allan if I am wrong.
Allan