Hidden title string sorting

Sort data as a string based on an attribute on an empty element.

  • Author: Allan Jardine
  • Deprecated: This plug-in has been deprecated and replaced with other functionality. Please see the detailed description below for more information.

Just like the hidden title numeric sorting plug-in, this sorting plug-in will take the information to be sorted on from the title attribute of a span element. The only difference is that it is string based sorting rather than numeric.

Note that the HTML5 data-sort attribute can be used to supply sorting data to DataTables and is preferable to using this method, which is therefore marked as deprecated.

Plug-in code

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "title-string-pre": function ( a ) {
        return a.match(/title="(.*?)"/)[1].toLowerCase();
    },

    "title-string-asc": function ( a, b ) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "title-string-desc": function ( a, b ) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
} );

CDN

This plug-in is available on the DataTables CDN:

JS

Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!

Example

$('#example').dataTable( {
     columnDefs: [
       { type: 'title-string', targets: 0 }
     ]
  } );