# ColOps | tablefilter v0.5.3 API Document

    import ColOps from 'tablefilter/src/extensions/colOps/colOps.js'

public class | source

# ColOps

#### Extends:

Feature → ColOps

Column calculations extension

## Constructor Summary

Public Constructor
public | constructor (tf: TableFilter, opts: Object) Creates an instance of ColOps |

## Member Summary

Public Members
public | colIndexes : Array List of columns' indexes for calculations |
public | decimalPrecisions : Array List of decimal precision for calculation results |
public | excludeRows : Array List of row indexes excluded from calculations |
public | formatResults : Array List of format objects used for formatting the result - refer to https://github.com/componitable/format-number to check configuration options |
public | initialized : boolean |
public | labelIds : Array List of DOM element IDs containing column's calculation result |
public | onAfterOperation : Function Callback fired after columns operations are completed |
public | onBeforeOperation : Function Callback fired before columns operations start |
public | operations : Array List of operations - possible values: 'sum', 'mean', 'min', 'max', 'median', 'q1', 'q3' |
public | opts : Object Configuration options |
public | outputTypes : Array List of write methods used to write the result - possible values: 'innerHTML', 'setValue', 'createTextNode' |
public | totRowIndexes : Array List of row indexes displaying the results |

## Method Summary

Public Methods

public

calcAll ()

Calculates columns' values Configuration options are stored in 'opts' property

- 'id' contains ids of elements showing result (array)
- 'col' contains the columns' indexes (array)
- 'operation' contains operation type (array, values: 'sum', 'mean', 'min', 'max', 'median', 'q1', 'q3')
- 'write_method' array defines which method to use for displaying the result (innerHTML, setValue, createTextNode) - default: 'innerHTML'
- 'tot_row_index' defines in which row results are displayed (integers array)

public | calcMax (values: Array): Number Calculate the max value of passed values. |
public | calcMean (values: Array): Number Calculate the mean of passed values. |
public | calcMedian (values: Array): Number Calculate the median of passed values. |
public | calcMin (values: Array): Number Calculate the min value of passed values. |
public | calcQ1 (values: Array): Number Calculate the lower quartile of passed values. |
public | calcQ3 (values: Array): Number Calculate the upper quartile of passed values. |
public | calcSum (values: Array): Number Calculate the sum of passed values. |
public | columnCalc (colIndex: Number, operation: String, precision: Number): Number Make desired calculation on specified column. |
public | destroy () Remove extension |
public | init () Initializes ColOps instance |
public | sortColumnValues (values: Array, sorter: Function): Array Sort passed values with supplied sorter function. |

## Inherited Summary

From class Feature
public | config : Object TableFilter configuration |
public | emitter : Emitter TableFilter emitter instance |
public | enabled : Boolean TableFilter feature setting |
public | feature : String Feature name |
public | initialized : Boolean Field indicating whether Feature is initialized |
public | tf : TableFilter TableFilter instance |
public | destroy () Destroy the feature |
public | disable () Disable the feature |
public | enable () Enable the feature |
public | init () Initialize the feature |
public | isEnabled (): Boolean Indicate whether the feature is enabled or not |
public | reset () Reset the feature after being disabled |

## Public Constructors

### public constructor(tf: TableFilter, opts: Object) source

Creates an instance of ColOps

#### Override:

Feature#constructor

#### Params:

Name | Type | Attribute | Description
tf | TableFilter |  | TableFilter instance
opts | Object |  | Configuration object

## Public Members

### public colIndexes: Array source

List of columns' indexes for calculations

### public decimalPrecisions: Array source

List of decimal precision for calculation results

### public excludeRows: Array source

List of row indexes excluded from calculations

### public formatResults: Array source

List of format objects used for formatting the result - refer to https://github.com/componitable/format-number to check configuration options

### public initialized: boolean source

#### Override:

Feature#initialized

### public labelIds: Array source

List of DOM element IDs containing column's calculation result

### public onAfterOperation: Function source

Callback fired after columns operations are completed

### public onBeforeOperation: Function source

Callback fired before columns operations start

### public operations: Array source

List of operations - possible values: 'sum', 'mean', 'min', 'max', 'median', 'q1', 'q3'

### public opts: Object source

Configuration options

### public outputTypes: Array source

List of write methods used to write the result - possible values: 'innerHTML', 'setValue', 'createTextNode'

### public totRowIndexes: Array source

List of row indexes displaying the results

## Public Methods

### public calcAll() source

Calculates columns' values Configuration options are stored in 'opts' property

- 'id' contains ids of elements showing result (array)
- 'col' contains the columns' indexes (array)
- 'operation' contains operation type (array, values: 'sum', 'mean', 'min', 'max', 'median', 'q1', 'q3')
- 'write_method' array defines which method to use for displaying the result (innerHTML, setValue, createTextNode) - default: 'innerHTML'

- 'tot_row_index' defines in which row results are displayed (integers array)

- changes made by Nuovella: (1) optimized the routine (now it will only process each column once), (2) added calculations for the median, lower and upper quartile.

### public calcMax(values: Array): Number source

Calculate the max value of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public calcMean(values: Array): Number source

Calculate the mean of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public calcMedian(values: Array): Number source

Calculate the median of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public calcMin(values: Array): Number source

Calculate the min value of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public calcQ1(values: Array): Number source

Calculate the lower quartile of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public calcQ3(values: Array): Number source

Calculate the upper quartile of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public calcSum(values: Array): Number source

Calculate the sum of passed values.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values

#### Return:

Number

### public columnCalc(colIndex: Number, operation: String, precision: Number): Number source

Make desired calculation on specified column.

#### Params:

Name | Type | Attribute | Description
colIndex | Number |  | Column index

operation

String

- optional
- default: SUM

Operation type

precision | Number |  | Decimal precision

#### Return:

Number

### public destroy() source

Remove extension

#### Override:

Feature#destroy

### public init() source

Initializes ColOps instance

#### Override:

Feature#init

### public sortColumnValues(values: Array, sorter: Function): Array source

Sort passed values with supplied sorter function.

#### Params:

Name | Type | Attribute | Description

values

Array

- optional
- default: []

List of values to be sorted

sorter | Function |  | Sorter function

#### Return:

Array