X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6746dc89c47ed01b165cc1152533605f97eb8e8d..refs/heads/master:/docs/source/Number3.html diff --git a/docs/source/Number3.html b/docs/source/Number3.html index 9076b4a7..caf77203 100644 --- a/docs/source/Number3.html +++ b/docs/source/Number3.html @@ -3,8 +3,8 @@ The source code - - + + @@ -15,112 +15,56 @@ -
/**
- * @class Ext.Number
+  
/**
+ * A Column definition class which renders a numeric data field according to a {@link #format} string.
  *
- * A collection of useful static methods to deal with numbers
- * @singleton
+ *     @example
+ *     Ext.create('Ext.data.Store', {
+ *        storeId:'sampleStore',
+ *        fields:[
+ *            { name: 'symbol', type: 'string' },
+ *            { name: 'price',  type: 'number' },
+ *            { name: 'change', type: 'number' },
+ *            { name: 'volume', type: 'number' },            
+ *        ],
+ *        data:[
+ *            { symbol: "msft",   price: 25.76,  change: 2.43, volume: 61606325 },
+ *            { symbol: "goog",   price: 525.73, change: 0.81, volume: 3053782  },
+ *            { symbol: "apple",  price: 342.41, change: 1.35, volume: 24484858 },            
+ *            { symbol: "sencha", price: 142.08, change: 8.85, volume: 5556351  }            
+ *        ]
+ *     });
+ *     
+ *     Ext.create('Ext.grid.Panel', {
+ *         title: 'Number Column Demo',
+ *         store: Ext.data.StoreManager.lookup('sampleStore'),
+ *         columns: [
+ *             { text: 'Symbol',         dataIndex: 'symbol', flex: 1 },
+ *             { text: 'Current Price',  dataIndex: 'price',  renderer: Ext.util.Format.usMoney },
+ *             { text: 'Change',         dataIndex: 'change', xtype: 'numbercolumn', format:'0.00' },
+ *             { text: 'Volume',         dataIndex: 'volume', xtype: 'numbercolumn', format:'0,000' }
+ *         ],
+ *         height: 200,
+ *         width: 400,
+ *         renderTo: Ext.getBody()
+ *     });
  */
+Ext.define('Ext.grid.column.Number', {
+    extend: 'Ext.grid.column.Column',
+    alias: ['widget.numbercolumn'],
+    requires: ['Ext.util.Format'],
+    alternateClassName: 'Ext.grid.NumberColumn',
 
-(function() {
-
-var isToFixedBroken = (0.9).toFixed() !== '1';
-
-Ext.Number = {
-    /**
-     * Checks whether or not the passed number is within a desired range.  If the number is already within the
-     * range it is returned, otherwise the min or max value is returned depending on which side of the range is
-     * exceeded. Note that this method returns the constrained value but does not change the current number.
-     * @param {Number} number The number to check
-     * @param {Number} min The minimum number in the range
-     * @param {Number} max The maximum number in the range
-     * @return {Number} The constrained value if outside the range, otherwise the current value
-     */
-    constrain: function(number, min, max) {
-        number = parseFloat(number);
-
-        if (!isNaN(min)) {
-            number = Math.max(number, min);
-        }
-        if (!isNaN(max)) {
-            number = Math.min(number, max);
-        }
-        return number;
-    },
-
-    /**
-     * Snaps the passed number between stopping points based upon a passed increment value.
-     * @param {Number} value The unsnapped value.
-     * @param {Number} increment The increment by which the value must move.
-     * @param {Number} minValue The minimum value to which the returned value must be constrained. Overrides the increment..
-     * @param {Number} maxValue The maximum value to which the returned value must be constrained. Overrides the increment..
-     * @return {Number} The value of the nearest snap target.
+    /**
+     * @cfg {String} format
+     * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column.
      */
-    snap : function(value, increment, minValue, maxValue) {
-        var newValue = value,
-            m;
-
-        if (!(increment && value)) {
-            return value;
-        }
-        m = value % increment;
-        if (m !== 0) {
-            newValue -= m;
-            if (m * 2 >= increment) {
-                newValue += increment;
-            } else if (m * 2 < -increment) {
-                newValue -= increment;
-            }
-        }
-        return Ext.Number.constrain(newValue, minValue,  maxValue);
-    },
-
-    /**
-     * Formats a number using fixed-point notation
-     * @param {Number} value The number to format
-     * @param {Number} precision The number of digits to show after the decimal point
-     */
-    toFixed: function(value, precision) {
-        if (isToFixedBroken) {
-            precision = precision || 0;
-            var pow = Math.pow(10, precision);
-            return (Math.round(value * pow) / pow).toFixed(precision);
-        }
-
-        return value.toFixed(precision);
-    },
+    format : '0,000.00',
 
-    /**
-     * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
-     * it is not.
-
-Ext.Number.from('1.23', 1); // returns 1.23
-Ext.Number.from('abc', 1); // returns 1
-
-     * @param {Mixed} value
-     * @param {Number} defaultValue The value to return if the original value is non-numeric
-     * @return {Number} value, if numeric, defaultValue otherwise
-     */
-    from: function(value, defaultValue) {
-        if (isFinite(value)) {
-            value = parseFloat(value);
-        }
-
-        return !isNaN(value) ? value : defaultValue;
+    constructor: function(cfg) {
+        this.callParent(arguments);
+        this.renderer = Ext.util.Format.numberRenderer(this.format);
     }
-};
-
-})();
-
-/**
- * This method is deprecated, please use {@link Ext.Number#from Ext.Number.from} instead
- *
- * @deprecated 4.0.0 Replaced by Ext.Number.from
- * @member Ext
- * @method num
- */
-Ext.num = function() {
-    return Ext.Number.from.apply(this, arguments);
-};
+});