/hippo/src/main/webapp/ext/src/data/SortTypes.js

http://hdbc.googlecode.com/ · JavaScript · 91 lines · 32 code · 8 blank · 51 comment · 2 complexity · 30b7cc14bc1964f523b5560c304d81ac MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.data.SortTypes
  9. * @singleton
  10. * Defines the default sorting (casting?) comparison functions used when sorting data.
  11. */
  12. Ext.data.SortTypes = {
  13. /**
  14. * Default sort that does nothing
  15. * @param {Mixed} s The value being converted
  16. * @return {Mixed} The comparison value
  17. */
  18. none : function(s){
  19. return s;
  20. },
  21. /**
  22. * The regular expression used to strip tags
  23. * @type {RegExp}
  24. * @property
  25. */
  26. stripTagsRE : /<\/?[^>]+>/gi,
  27. /**
  28. * Strips all HTML tags to sort on text only
  29. * @param {Mixed} s The value being converted
  30. * @return {String} The comparison value
  31. */
  32. asText : function(s){
  33. return String(s).replace(this.stripTagsRE, "");
  34. },
  35. /**
  36. * Strips all HTML tags to sort on text only - Case insensitive
  37. * @param {Mixed} s The value being converted
  38. * @return {String} The comparison value
  39. */
  40. asUCText : function(s){
  41. return String(s).toUpperCase().replace(this.stripTagsRE, "");
  42. },
  43. /**
  44. * Case insensitive string
  45. * @param {Mixed} s The value being converted
  46. * @return {String} The comparison value
  47. */
  48. asUCString : function(s) {
  49. return String(s).toUpperCase();
  50. },
  51. /**
  52. * Date sorting
  53. * @param {Mixed} s The value being converted
  54. * @return {Number} The comparison value
  55. */
  56. asDate : function(s) {
  57. if(!s){
  58. return 0;
  59. }
  60. if(Ext.isDate(s)){
  61. return s.getTime();
  62. }
  63. return Date.parse(String(s));
  64. },
  65. /**
  66. * Float sorting
  67. * @param {Mixed} s The value being converted
  68. * @return {Float} The comparison value
  69. */
  70. asFloat : function(s) {
  71. var val = parseFloat(String(s).replace(/,/g, ""));
  72. return isNaN(val) ? 0 : val;
  73. },
  74. /**
  75. * Integer sorting
  76. * @param {Mixed} s The value being converted
  77. * @return {Number} The comparison value
  78. */
  79. asInt : function(s) {
  80. var val = parseInt(String(s).replace(/,/g, ""), 10);
  81. return isNaN(val) ? 0 : val;
  82. }
  83. };