FormatContents class (Pivot)

FormatContents(oPivot)

new FormatContents(oPivot)

The FormatContents object holds the content-formats to apply on the pivot control. For instance, you can display the values in numeric format. The FormatContents / GetFormatContents() method returns the control's format-contents that specifies how a column or row can be displayed, formatted or converted.

By default, the FormatContents collection contains the following objects:

  • "numeric", to show the cells in numeric format
  • "currency", to show the cells as currency
  • "date", to show the cells in date format
Parameters:
Name Type Description
oPivot Pivot Indicates an object of Pivot type that owns the collection.
Example
oPivot.FormatContents.Add({key: "upper", expression: "type(value) = 4 ? upper(value) : value format ``"}), shows the value in uppercase.

Members

Count :number

The Count property returns the number of FormatOptions objects within the collection. The FormatOptions object defines the content formats that can be applied to the pivot columns, pivot rows, and total/subtotal fields in the pivot table. The content formats specify how a column or row can be displayed, formatted or converted. The Add, Remove and Clear methods affect the count of formats within the collection. The Count property can be used to iterate through all formats within the collection. The Item method can be used to access a specific format within the collection. By default, the FormatContents collection contains three content formats: "numeric" to show the cells in numeric format, "currency" to show the cells as currency, and "date" to show the cells in date format.
Type:
  • number
Example
0 {number}, there are no content formats defined in the collection
3 {number}, there are three content formats defined in the collection
Count

Methods

Add(oFormatOptions) → {FormatOptions}

The Add() method adds/updates the format based on its key. The FormatOptions object defines the content formats that can be applied to the pivot columns, pivot rows, and total/subtotal fields in the pivot table. The content formats specify how a column or row can be displayed, formatted or converted. The Item method can be used to access a specific format within the collection. The FormatContents.forEach() method enumerates the FormatOptions objects within the current collection. By default, the FormatContents collection contains three content formats: "numeric" to show the cells in numeric format, "currency" to show the cells as currency, and "date" to show the cells in date format.
Parameters:
Name Type Description
oFormatOptions object Indicates an object of FormatOptions type that holds attributes of the format to add/replace.
Returns:
Returns undefined (no key provided), or an the object being added of FormatOptions type that holds attributes of the format being added
Type
FormatOptions
Example
The following sample adds a content format to show the values in scientific format:

 oPivot.FormatContents.Add(
 {
   key: "scientific",
   expression: "value format `%.2E` replace `+00` with `+`"
 })
Add

Clear()

The Clear() method clears the FormatOptions objects within the collection. The Remove method can be used to remove a specific format within the collection, by key. The FormatContents.Count property can be used to iterate through all formats within the collection. The Item method can be used to access a specific format within the collection. The FormatContents.forEach() method enumerates the FormatOptions objects within the current collection. By default, the FormatContents collection contains three content formats: "numeric" to show the cells in numeric format, "currency" to show the cells as currency, and "date" to show the cells in date format.
Example
oPivot.FormatContents.Clear(), clears all format-options from the control's format-contents, to no longer show the cells in numeric format, or as currency, or in date format
Clear

Item(key) → {FormatOptions}

The Item() property gets the format based on the key. The Count property can be used to iterate through all formats within the collection. The FormatContents.forEach() method enumerates the FormatOptions objects within the current collection. By default, the FormatContents collection contains three content formats: "numeric" to show the cells in numeric format, "currency" to show the cells as currency, and "date" to show the cells in date format.
Parameters:
Name Type Description
key string Specifies the key of the format to request.
Returns:
Returns undefined (no format found), or an the object being added of FormatOptions type that holds attributes of the format being added
Type
FormatOptions
Example
oPivot.FormatContents.Item("currency"), gets the "currency" format-options from the control's format-contents, to show the cells as currency
Item

Remove(key) → {boolean}

The Remove() method removes the format giving its key. The Clear method can be used to remove all formats within the collection. The Count property can be used to iterate through all formats within the collection. The Item method can be used to access a specific format within the collection. By default, the FormatContents collection contains three content formats: "numeric" to show the cells in numeric format, "currency" to show the cells as currency, and "date" to show the cells in date format.
Parameters:
Name Type Description
key string Specifies the key of the format to remove.
Returns:
Returns true, if the key has been removed
Type
boolean
Example
oPivot.FormatContents.Remove("currency"), removes the "currency" format-options from the control's format-contents, to no longer show the cells as currency
Remove

forEach(callback, thisArg)

The forEach() method enumerates the FormatOptions objects within the current collection. The Count property counts the number of formats within the collection. The Item method can be used to access a specific format within the collection, by key. By default, the FormatContents collection contains three content formats: "numeric" to show the cells in numeric format, "currency" to show the cells as currency, and "date" to show the cells in date format.
Parameters:
Name Type Description
callback callback Indicates a function of callback(oFormatOptions) type, where
oFormatOptions {object}, indicates the format of FormatOptions type
thisArg any Specifies the value of "this" keyword during the callback. If missing it refers to the current collection.
Example
The following sample enumerates all format-contents within the control, and displays their keys:

 oPivot.FormatContents.forEach(function(element, index)
 {
   console.log(exontrol.ToString.Quote(element));
 })
forEach