Sencha Documentation

Reusable data formatting functions

Properties

 
currencyAtEnd : Boolean
This may be set to true to make the currency function append the currency sign to the formatted value. This defaults ...

This may be set to true to make the currency function append the currency sign to the formatted value.

This defaults to false, but may be overridden in a locale file.

 
The number of decimal places that the currency function displays. This defaults to 2, but may be overridden in a loca...

The number of decimal places that the currency function displays.

This defaults to 2, but may be overridden in a locale file.

 
currencySign : String

The currency sign that the currency function displays.

This defaults to $, but may be overridden in a locale file.

The currency sign that the currency function displays.

This defaults to $, but may be overridden in a locale file.

 
The character that the number function uses as a decimal point. This defaults to ., but may be overridden in a locale...

The character that the number function uses as a decimal point.

This defaults to ., but may be overridden in a locale file.

 
The character that the number function uses as a thousand separator. This defaults to ,, but may be overridden in a l...

The character that the number function uses as a thousand separator.

This defaults to ,, but may be overridden in a locale file.

Methods

 
currency( Number/String value, String sign, Number decimals, Boolean end ) : String
Format a number as a currency
Format a number as a currency

Parameters

  • value : Number/String
    The numeric value to format
  • sign : String
    The currency sign to use (defaults to currencySign)
  • decimals : Number
    The number of decimals to use for the currency (defaults to currencyPrecision)
  • end : Boolean
    True if the currency sign should be at the end of the string (defaults to currencyAtEnd)

Returns

  • String   The formatted currency string
 
date( String/Date value, [String format] ) : String
Formats the passed date using the specified format pattern.
Formats the passed date using the specified format pattern.

Parameters

  • value : String/Date
    The value to format. If a string is passed, it is converted to a Date by the Javascript Date object's parse() method.
  • format : String
    (Optional) Any valid date format string. Defaults to Ext.Date.defaultFormat.

Returns

  • String   The formatted date string.
 
dateRenderer( String format ) : Function
Returns a date rendering function that can be reused to apply a date format multiple times efficiently
Returns a date rendering function that can be reused to apply a date format multiple times efficiently

Parameters

Returns

  • Function   The date formatting function
 
defaultValue( Mixed value, String defaultValue ) : String
Checks a reference and converts it to the default value if it's empty
Checks a reference and converts it to the default value if it's empty

Parameters

  • value : Mixed
    Reference to check
  • defaultValue : String
    The value to insert of it's undefined (defaults to "")

Returns

  • String   undefined
 
escapeRegex( String str ) : String
Escapes the passed string for use in a regular expression
Escapes the passed string for use in a regular expression

Parameters

  • str : String

Returns

  • String   undefined
 
fileSize( Number/String size ) : String
Simple format for a file size (xxx bytes, xxx KB, xxx MB)
Simple format for a file size (xxx bytes, xxx KB, xxx MB)

Parameters

  • size : Number/String
    The numeric value to format

Returns

  • String   The formatted file size
 
lowercase( String value ) : String
Converts a string to all lower case letters
Converts a string to all lower case letters

Parameters

  • value : String
    The text to convert

Returns

  • String   The converted text
 
math : Function
It does simple math for use in a template, for example:var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")...
It does simple math for use in a template, for example:
var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
 
nl2br( String The ) : String
Converts newline characters to the HTML tag <br/>
Converts newline characters to the HTML tag <br/>

Parameters

  • The : String
    string value to format.

Returns

  • String   The string with embedded <br/> tags in place of newlines.
 
number( Number v, String format ) : String
Formats the passed number according to the passed format string. The number of digits after the decimal separator cha...

Formats the passed number according to the passed format string.

The number of digits after the decimal separator character specifies the number of decimal places in the resulting string. The local-specific decimal character is used in the result.

The presence of a thousand separator character in the format string specifies that the locale-specific thousand separator (if any) is inserted separating thousand groups.

By default, "," is expected as the thousand separator, and "." is expected as the decimal separator.

New to Ext4

Locale-specific characters are always used in the formatted output when inserting thousand and decimal separators.

The format string must specify separator characters according to US/UK conventions ("," as the thousand separator, and "." as the decimal separator)

To allow specification of format strings according to local conventions for separator characters, add the string /i to the end of the format string.

examples (123456.789):
0 - (123456) show only digits, no precision
0.00 - (123456.78) show only digits, 2 precision
0.0000 - (123456.7890) show only digits, 4 precision
0,000 - (123,456) show comma and digits, no precision
0,000.00 - (123,456.78) show comma and digits, 2 precision
0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision
To allow specification of the formatting string using UK/US grouping characters (,) and decimal (.) for international numbers, add /i to the end. For example: 0.000,00/i

Parameters

  • v : Number
    The number to format.
  • format : String
    The way you would like to format this text.

Returns

  • String   The formatted number.
 
numberRenderer( String format ) : Function
Returns a number rendering function that can be reused to apply a number format multiple times efficiently
Returns a number rendering function that can be reused to apply a number format multiple times efficiently

Parameters

  • format : String
    Any valid number format string for number

Returns

  • Function   The number formatting function
 
parseBox( Number|String v ) : Object
Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations (e.g. 10, ...
Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)

Parameters

  • v : Number|String
    The encoded margins

Returns

  • Object   An object with margin sizes for top, right, bottom and left
 
plural( Number value, String singular, [String plural] ) : Void
Selectively do a plural form of a word based on a numeric value. For example, in a template, {commentCount:plural("Co...
Selectively do a plural form of a word based on a numeric value. For example, in a template, {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments" if the value is 0 or greater than 1.

Parameters

  • value : Number
    The value to compare against
  • singular : String
    The singular form of the word
  • plural : String
    (optional) The plural form of the word (defaults to the singular with an "s")

Returns

  • Void
 
round( Number/String value, Number precision ) : Number
Rounds the passed number to the required decimal precision.
Rounds the passed number to the required decimal precision.

Parameters

  • value : Number/String
    The numeric value to round.
  • precision : Number
    The number of decimal places to which to round the first parameter's value.

Returns

  • Number   The rounded value.
 
stripScripts( Mixed value ) : String
Strips all script tags
Strips all script tags

Parameters

  • value : Mixed
    The text from which to strip script tags

Returns

  • String   The stripped text
 
stripTags( Mixed value ) : String
Strips all HTML tags
Strips all HTML tags

Parameters

  • value : Mixed
    The text from which to strip tags

Returns

  • String   The stripped text
 
substr( String value, Number start, Number length ) : String
Returns a substring from within an original string
Returns a substring from within an original string

Parameters

  • value : String
    The original text
  • start : Number
    The start index of the substring
  • length : Number
    The length of the substring

Returns

  • String   The substring
 
trim( String value ) : String
Trims any whitespace from either side of a string
Trims any whitespace from either side of a string

Parameters

  • value : String
    The text to trim

Returns

  • String   The trimmed text
 
undef( Mixed value ) : Mixed
Checks a reference and converts it to empty string if it is undefined
Checks a reference and converts it to empty string if it is undefined

Parameters

  • value : Mixed
    Reference to check

Returns

  • Mixed   Empty string if converted, otherwise the original value
 
uppercase( String value ) : String
Converts a string to all upper case letters
Converts a string to all upper case letters

Parameters

  • value : String
    The text to convert

Returns

  • String   The converted text
 
usMoney( Number/String value ) : String
Format a number as US currency
Format a number as US currency

Parameters

  • value : Number/String
    The numeric value to format

Returns

  • String   The formatted currency string