e33985587b5f1345b43c260fd3ea8b98ce0c737b.svn-base 2.1 KB

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