mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-03 07:03:33 +02:00
Page:
3.2 Column operations
Pages
1.0 Configuration
1.01 Appearance
1.02 Main features
1.03 Grid layout
1.04 Paging
1.05 Drop down filter
1.06 Checklist filter
1.07 Rows counter
1.08 Loading indicator
1.09 Submit and reset button
1.10 Status bar
1.11 Data types
1.12 Themes
1.13 Help instructions
1.14 Popup filters
1.15 No results message
1.16 Highlight keywords
1.17 State
1.18 Mark active columns
1.19 Toolbar
1.20 Single filter
2.0 TableFilter class
2.1 Public properties
2.2 Public methods
3.0 Extensions
3.1 Advanced grid
3.1 Sort
3.2 Column operations
3.3 Filters visibility
3.4 Columns visibility
4. Filter operators
Home
Obsolete
TODO
10
3.2 Column operations
koalyptus edited this page 2017-03-25 18:02:25 +11:00
This extension allows TableFilter
to perform calculations on a column basis. Those are the operations that are currently possible:
- sum
- mean
- median
- min
- max
- lower quartile
- upper quartile
To get the colOps
extension instance:
var colOps = tf.extension('colOps');where
tf
is an instance of TableFilter
.
Property | Type | Description | Remarks | Example |
---|---|---|---|---|
name | string | name of the extension, it should match the name of the directory and of the file, in this case 'colOps'. this extension can perform the following calculations on a specified column:
|
Special credit to Nuovella Williams for optimising the calculations and adding the "median", "lower quartile" and "upper quartile" calculations. | var tfConfig = { extensions: [{ name: 'colOps' }] }; |
id | array | list of the ids of elements displaying the calculation results. | var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'] }] }; |
|
col | array | collection of column indexes on which calculations will be performed. |
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4] }] }; |
|
operation | array | list of the type of calculation per column, possible values: 'sum', 'mean', 'min', 'max', 'median', 'q1', 'q3' |
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'] }] }; |
|
write_method | array | list instructing the extension how to write the calculation result, possible values: 'innerHTML', 'setValue', 'createTextNode' (default - 'innerHTML') |
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'], write_method: ['innerHTML', 'setValue'] }] }; |
|
format_result | array | list of format objects used for formatting operation results | refer to https://github.com/componitable/format-number to check the configuration options. By default, `ColOps` will match the current number format in terms of thousands and decimal separators based on the column type, (`number` or `formatted-number`) |
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'], write_method: ['innerHTML', 'setValue'], format_result: [{ prefix: '$' }, { suffix: '/unit' }] }] }; |
exclude_row | array | collection of row indexes from be excluded from the calculation |
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'], write_method: ['innerHTML', 'setValue'] exclude_row: [7, 18] }] }; |
|
decimal_precision | function | the decimal precision to be applied on the calculation result per column |
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'], write_method: ['innerHTML', 'setValue'] exclude_row: [7, 18], decimal_precision: [2, 1] }] }; |
|
on_before_operation | function | callback fired before the column calculations are performed (default - null) | 1 parameter:
|
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'], write_method: ['innerHTML', 'setValue'] exclude_row: [7, 18], decimal_precision: [2, 1], on_before_operation: function(o){ console.log(o.getExtension('colOps')); } }] }; |
on_after_operation | function | callback fired after the column calculations are performed (default - null) | 1 parameter:
|
var tfConfig = { extensions: [{ name: 'colOps', id: ['col2Total', 'col4Mean'], col: [2, 4], operation: ['sum', 'mean'], write_method: ['innerHTML', 'setValue'] exclude_row: [7, 18], decimal_precision: [2, 1], on_after_operation: function(o){ console.log(o.getExtension('colOps')); } }] }; |
Assuming TableFilter
is already instanciated:
var tf = new TableFilter('my-table-id');
Event | Description | Remarks | Example |
---|---|---|---|
before-column-calc | Event emitted just before a column values calculation is performed |
Subscribers receive the following parameters:
|
tf.emitter.on(['before-column-calc'], function(tf, colOps, colIndex, values, operation, precision) { console.log(tf, colOps, colIndex, values, operation, precision); }); |
column-calc | Event emitted after a calculation is performed |
Subscribers receive the following parameters:
|
tf.emitter.on(['column-calc'], function(tf, colOps, colIndex, result, operation, precision) { console.log(tf, colOps, colIndex, result, operation, precision); }); |