<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
- <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
- <script type="text/javascript" src="../prettify/prettify.js"></script>
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
</script>
</head>
<body onload="prettyPrint(); highlight();">
- <pre class="prettyprint lang-js"><span id='Ext-Number'>/**
-</span> * @class Ext.Number
+ <pre class="prettyprint lang-js"><span id='Ext-grid-column-Number'>/**
+</span> * 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 = {
-<span id='Ext-Number-method-constrain'> /**
-</span> * Checks whether or not the current 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;
- },
-
-<span id='Ext-Number-method-toFixed'> /**
-</span> * 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);
- },
-
-<span id='Ext-Number-method-from'> /**
-</span> * 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
+<span id='Ext-grid-column-Number-cfg-format'> /**
+</span> * @cfg {String} format
+ * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column.
*/
- from: function(value, defaultValue) {
- if (isFinite(value)) {
- value = parseFloat(value);
- }
+ format : '0,000.00',
- return !isNaN(value) ? value : defaultValue;
+ constructor: function(cfg) {
+ this.callParent(arguments);
+ this.renderer = Ext.util.Format.numberRenderer(this.format);
}
-};
-
-})();
-
-<span id='Ext-method-num'>/**
-</span> * 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);
-};</pre>
+});</pre>
</body>
</html>