Title: Custom sorting for grades
Last modified: August 30, 2016

---

# Custom sorting for grades

 *  Resolved [Jeff Barnes](https://wordpress.org/support/users/jeff-barnes/)
 * (@jeff-barnes)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/)
 * I’m trying to get a column to read as a “grade”. Thus, an A+ would be the top,
   then A, then A-, so on.
 * Based on a previous discussion of custom sorting ([https://wordpress.org/support/topic/custom-sorting-2?replies=2](https://wordpress.org/support/topic/custom-sorting-2?replies=2)),
   I tried implementing this, but I’m getting nowhere after a few hours of experimentation.
   Also, no errors in JS console, so nothing to debug on.
 * You can see the result at [http://themeparkwizards.com/blog/index.php/2015/09/19/epcot-101-table-dining-experiences/](http://themeparkwizards.com/blog/index.php/2015/09/19/epcot-101-table-dining-experiences/)
 * 1) I added this to jquery.datatables.sorting-plugins.js in tablepress-datatables-
   sorting-plugins (after installing the plugin) at the end of the file:
 * jQuery.fn.dataTableExt.aTypes.unshift( function ( data ) {
 *  var re = new RegExp( “^[A-F][\+\-]?$” ); // Init the regex just once for speed
 *  jQuery.fn.dataTableExt.aTypes.unshift( function ( data ) {
 *  if ( typeof data !== ‘string’ || !re.test( data ) ) {
    return null;
 *  }
 *  return ‘grades’;
 *  } );
 * } );
 * jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    ‘grades-pre’ : function ( a ){
   switch( a ) { case “A+”: return 12; case “A”: return 11; case “A-“: return 10;
   case “B+”: return 9; case “B”: return 8; case “B-“: return 7; case “C+”: return
   6; case “C”: return 5; case “C-“: return 4; case “D+”: return 3; case “D”: return
   2; case “D-“: return 1; case “F”: return 0; default: return 0; } },
 *  “grades-asc”: function ( a, b ) {
    if ( 0 == a ) return 1; if ( 0 == b ) return-
   1; return ((a < b) ? -1 : ((a > b) ? 1 : 0)); },
 *  “grades-desc”: function ( a, b ) {
    if ( 0 == a ) return -1; if ( 0 == b ) return
   1; return ((a < b) ? 1 : ((a > b) ? -1 : 0)); } } );
 * 2. I added this to the table itself under Custom Commands:
 * “columnDefs”: [ { “type”: “grades”, “targets”: [ 1,2,3,4 ] } ]
 * Still nothing. Any help you can render would be appreciated. Thanks!
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564582)
 * Hi,
 * thanks for your question, and sorry for the trouble.
 * From what I can see, you’ll simply have to add this to the minified file jquery.
   datatables.sorting-plugins.min.js as well.
 * Regards,
    Tobias
 *  Thread Starter [Jeff Barnes](https://wordpress.org/support/users/jeff-barnes/)
 * (@jeff-barnes)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564617)
 * Tried that, too, but still no results.
 * I wonder, should the unshift and/or the extend be merged with the existing code,
   or should it be just pasted at the end after the existing closing } ); ?
 * Thanks.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564626)
 * Hi,
 * no, I don’t think that the unshift/extend have to merged, but it would be possible.
 * Now, unfortunately, I couldn’t check other things, as the URL that you posted
   only gives a “Not found” error for me now 🙁
 * Regards,
    Tobias
 *  Thread Starter [Jeff Barnes](https://wordpress.org/support/users/jeff-barnes/)
 * (@jeff-barnes)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564636)
 * [http://themeparkwizards.com/blog/index.php/2015/09/22/epcot-101-table-dining-experiences/](http://themeparkwizards.com/blog/index.php/2015/09/22/epcot-101-table-dining-experiences/)
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564643)
 * Hi,
 * I just checked that link, and for me the sorting is working just fine – except
   that ascending and descending seems to be switched, so you’ll just have to switch
   that in the code as well.
 * Regards,
    Tobias
 *  Thread Starter [Jeff Barnes](https://wordpress.org/support/users/jeff-barnes/)
 * (@jeff-barnes)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564649)
 * Ah. Looks like publishing it made it work? Dunno. Sorry for the bother, but thanks
   for the excellent service!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564650)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * Best wishes,
    Tobias
 * P.S.: In case you haven’t, please [rate TablePress](https://wordpress.org/support/view/plugin-reviews/tablepress)
   here in the plugin directory. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Custom sorting for grades’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [custom sorting](https://wordpress.org/support/topic-tag/custom-sorting/)

 * 7 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/custom-sorting-for-grades/#post-6564650)
 * Status: resolved