SortTypes.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:2k
源码类别:

中间件编程

开发平台:

JavaScript

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