I am trying to implement a custom sort, and it is not working. I am a noob to datatables and have taken over a system where they were used extensively. I followed some tutorials and built a custom sort. Looking for a little help as to why the custom sort I put in is not being called.
The mDataProp patient_name comes through like this "Doe, John" some are blank "". I want to split the patient name on the , and then sort on the last name. Currently it sorts on the first name after the "," by default. So "Rose, Axl" orders before "Michaels, Brett"... when what I want is "Michaels, Brett" followed by "Rose, Axl".
one other problem I have is the bVisisble: false not working with the bSaveState: true... using Chrome v 33. But that's a discussion for another day unless someone has an answer right away.
The mDataProp patient_name comes through like this "Doe, John" some are blank "". I want to split the patient name on the , and then sort on the last name. Currently it sorts on the first name after the "," by default. So "Rose, Axl" orders before "Michaels, Brett"... when what I want is "Michaels, Brett" followed by "Rose, Axl".
one other problem I have is the bVisisble: false not working with the bSaveState: true... using Chrome v 33. But that's a discussion for another day unless someone has an answer right away.
var activityTable; $(function() { jQuery.fn.dataTableExt.oSort['full_name-asc'] = function(x,y) { var last_name_x = x.split(",")[0]; var last_name_y = y.split(",")[0]; return ((last_name_x < last_name_y) ? -1 : ((last_name_x > last_name_y) ? 1 : 0)); }; jQuery.fn.dataTableExt.oSort['full_name-desc'] = function(x,y) { var last_name_x = x.split(",")[0]; var last_name_y = y.split(",")[0]; return ((last_name_x < last_name_y) ? 1 : ((last_name_x > last_name_y) ? -1 : 0)); }; activityTable = $('#activity_table').dataTable( { "bStateSave": false, "iCookieDuration": 86400, "sPaginationType": "full_numbers", "bServerSide": true, "sAjaxSource": "/activity/listajax/id/<?php echo isset ( $id ) ? "$id/" : "null/"; ?>patient_id/<?php echo isset ( $patient_id ) ? "$patient_id/" : "0/"; ?>client_id/<?php echo isset ( $client_id ) ? "$client_id/" : "0/"; ?><?php echo isset ( $popup ) && $popup ? "popup/1/" : "" ?>", "bJQueryUI": true, "bProcessing": true, "iDisplayLength": 50, "aaSorting": [[ 0, "desc" ]], "fnPreDrawCallback": function(){ $(".dataTables_processing").html('<?php echo Controller::ajax_loading (); ?>'); }, "fnInitComplete": function(oSettings, json) { }, "fnServerData": function ( sSource, aoData, fnCallback ) { $.getJSON( sSource, aoData, function (json) { if (json.error != undefined) { window.location = "/login/"; } else { fnCallback(json); } } ); }, "aoColumns": [ {"mDataProp": "date"}, {"mDataProp": "organization_name"}, {"sType": "full_name", "mDataProp": "patient_name"}, {"mDataProp": "lastname","bVisible" : false}, {"mDataProp": "mr_number"}, {"mDataProp": "contact_type"}, {"mDataProp": "user_name"}, {"mDataProp": "is_submitted"}, {"mDataProp": "buttons", "bSortable" : false, "bSearchable": false} ] }); activityTable.fnSetFilteringDelay(500); $("#extend_search").change(function(){ if($(this).attr('checked')) { val = 1; } else { val = 0; } var today = new Date(); var expire = new Date(); expire.setTime(today.getTime()+720000); document.cookie = "search_activity="+val+";expires="+expire.toGMTString()+";path=/"; activityTable.fnReloadAjax(); }); });