Hey all,
  Just thought I'd give back to the community and offer up a simple
addition to the great tablesorter plugin by Christian Bach (http://
motherrussia.polyester.se).

  I needed a simple sorter based on filesize, and it didn't quite work
with the generic sorter.  Thanks to the great structure of his code,
it was a simple task.. easy as:

<code>
        $.tableSorter.parsers.filesize = {
            id: 'filesize',
            is: function(s) {
                return s.match( new RegExp( /[0-9]+(\.[0-9]+)?\ (KB|B|GB|MB|
TB)/ ) );
            },
            format: function(s) {
                var suf = s.match( new RegExp( /(KB|B|GB|MB|TB)$/ ) )[1];
                var num = parseFloat( s.match( new RegExp( /^[0-9]+(\.
[0-9]+)?/ ) )[0] );

                switch( suf ) {
                    case 'B':
                        return num;
                    case 'KB':
                        return num * 1024;
                    case 'MB':
                        return num * 1024 * 1024;
                    case 'GB':
                        return num * 1024 * 1024 * 1024;
                    case 'TB':
                        return num * 1024 * 1024 * 1024 * 1024;
                }
            },
            sorter: $.tableSorter.sorters.numeric
        };

        /* dont forget to add it to the collection */
        $.tableSorter.analyzer.add($.tableSorter.parsers.filesize);
</code>

Reply via email to