I needed to be able to sort on a column with file sizes:
the following seems to work but I'm sure one of you experts will come
up with something more efficient:

HtmlTable.Parsers.bytes = {

        match: /^\d+[^\d.,]*$/,
    convert: function() {
        var str = this.get('text');
                        var number      = str.toFloat();
                var type        = str.replace(/(0-9.|[0-9.])/g, "").trim
().toUpperCase();
                 switch(type) {
                                case 'B':
                                        return number;
                                        break;
                                case 'KB':
                                        return number*1024;
                                        break;
                                case 'MB':
                                        return number*[Math.pow(1024,2)];
                                        break;
                                case 'GB':
                                        return number*[Math.pow(1024,3)];
                                        break;
                                default:
                                        return number;
                        }
    },
    number: true
};

Reply via email to