Initializing help system before first use

AutoTable

Uses provided entity information to build an Insight Table. Data is loaded automatically from the Insight API. AutoTable adds one column for each shared index set and one column for each array entity identified in the entities argument.

You can gain access to the underlying Insight Table object and from that the DataTable object too.

Method summary

name description
destroy Destroy the AutoTable instance. This will destroy the underlying DataTable and remove any DOM from within the table.
onDataSaved Attach a data saved callback.
constructor

Constructor

new AutoTable ( config )

Create a new AutoTable instance using table referenced with passed in id.

Parameters:
params
Name Type Description
config
type
AutoTable~Config
details

Members

members
table - {
type
Table }
The underlying Insight Table object.
details

Methods

method
destroy ( remove )

Destroy the AutoTable instance. This will destroy the underlying DataTable and remove any DOM from within the table.

Parameters:
params
Name Type Argument Default Description
remove
type
boolean
optional  false Whether to remove the table element or just remove AutoTable handlers. If destroy is called before an update (to refresh the table data) you probably want to omit this parameter or set it to false.
details
Back to Top
method
onDataSaved ( callback )

Attach a callback that will be called on save of any element associated with this AutoTable instance.

Parameters:
params
Name Type Description
callback
type
AutoTable~DataSavedCallback
Called when an entity has been successfully updated
details
Example
examples
var table = new insight.components.AutoTable(...);
table.onDataSaved(function(scenario, entity, value) {
    console.log('table 1 data saved: ' + scenario.getId() + ' - ' + entity.getName() + ' - ', value);
});
Back to Top

Type Definitions

method
Add ( autotable ) → {boolean}

Callback function for AutoTable-Add. Overriding this behaviour will make it your responsibility to add the DOM elements representing the row to the AutoTable.

Parameters:
params
Name Type Description
autotable
type
AutoTable
Table to which rows are to be added
details
Returns:
returns table
Type Description
type
boolean
Return true if the row was successfully added
Back to Top
members
ColumnOptions - {
type
Object }
Data structure passed to AutoTable.
details
Properties:
properties
Name Type Argument Default Description
name
type
string
Name of the entity to use for this column
scenario
type
Scenario
optional  The scenario to use for this column. Falls back to the default scenario assigned to the table
filters
type
AutoTable~ColumnOptions~Filter
optional  A map of index entity name to fixed (filtered) value(s). If this column has more indices than the column with the least number of indices then you must give fixed values for the extra indices.
sortByFormatted
type
boolean
optional  false Use formatted values for sorting. This is ignored if you supply your own render function.
filterByFormatted
type
boolean
optional  Use formatted values for filtering. This defaults to false unless the entity has a label in which case the default is true. This is ignored if you supply your own render function.
disableSetSorting
type
boolean
optional  false When applied to an index column, this will prevent set sorting from being applied to the column. Default table sorting will be used instead. This option is provided to reduce sorting overhead where performance is being affected.
title
type
string
optional  Title for the table column. Defaults to entity alias then entity name
width
type
string
optional  CSS width value
visible
type
boolean
optional  true Show or hide the column. Defaults to visible.
style
type
string
optional  Element class for the column
render
type
Table~RenderCallback
optional  Callback to custom render the cell. Overrides any default entity rendering.
editable
type
boolean
optional  false Whether cells in this column are editable or not
editorOptionsSet
type
string
optional  Name of a set entity to use for select options. This will display labels if a labels entity is defined against this set.
editorOptions
type
Table~EditorOptionsCallback
optional  A function that returns either an array of primitive values to display or a map object of values and display text to use for the select options.
selectNull
type
boolean
optional  false Enables array elements to be removed using a blank option added to the top of the select input
checkedValue
type
*
optional  The value to set the cell data to if input type is checkbox and it is checked
uncheckedValue
type
*
optional  The value to set the cell data to if input type is checkbox and it is not checked
editorValidate
type
AutoTable~EditorValidateCallback
optional  A callback to validate each cell edit in this column
editorType
type
Table.EditorType
optional  The editor type to use, in edit mode, for cells in this column. If not specified then it will be autodetected based on entity type.
members
Config - {
type
object }
Configuration object parameter for AutoTable.
details
Properties:
properties
Name Type Argument Default Description
tableId
type
string
DOM id of table element
scenario
type
Scenario
The default scenario for all bound entities in the table
selectionAndNavigation
type
boolean
optional  true Enable/disable table navigation, selection and clipboard
alwaysShowSelection
type
boolean
optional  false Whether to display selection on inactive tables.
addRemoveRow
type
boolean | string
optional  false Enable the add/remove row feature. If you set this value to be the string 'addrow-autoinc' it will switch the behaviour to allow new index values to be created, incrementing from the highest value in the set.
columnOptions
type
Array.<AutoTable~ColumnOptions>
optional 
indicesOptions
type
Object.<string, (AutoTable~IndicesOptions|Array.<AutoTable~IndicesOptions>)>
optional  Map of set name to indices options
overrides
type
Object.<string, *>
optional  key-value pairs that are pass into the DataTables library, DataTables options reference
Properties
properties
Name Type Argument Default Description
columnFilter
type
boolean
optional  false Triggers column filters to be added to the table
addRow
type
AutoTable~Add
optional  Hook for replacement of entire functionality to add a row
deleteRow
type
AutoTable~Remove
optional  Hook for replacement of entire functionality to remove row
preAdd
type
AutoTable~RowCallback
optional  Hook for validation or other actions prior to adding a row
preRemove
type
AutoTable~RowCallback
optional  Hook for validation or other actions prior to removing a row
postAdd
type
AutoTable~RowCallback
optional  Hook for notification after a row has been added
postRemove
type
AutoTable~RowCallback
optional  Hook for notification after a row has been removed
onDataSaved
type
AutoTable~DataSavedCallback
optional  Hook for notification after data has been saved
rowFilter
type
AutoTable~RowFilterCallback
optional  Called for each row in the table to determine whether it should be kept or discarded
saveState
type
boolean
optional  true Save table state in user's browser session so that user settings (e.g. page, sorting and search) are preserved if table data is reloaded.
method
DataSavedCallback ( scenario, entity, value )

Callback for AutoTable#onDataSaved.

Parameters:
params
Name Type Description
scenario
type
Scenario
The table column scenario
entity
type
ModelEntity
The table column entity. Passes undefined if it is an Insight Parameter type
value
type
string | object
Either a single value string or a composite key-value pair, in the case of an array) for the value saved. If removal of an array element then the value will be an empty string
details
Back to Top
method
EditorValidateCallback ( value, row, key ) → {Result}

Callback function for cell validation.

Parameters:
params
Name Type Description
value
type
PrimitiveType
The new value from the edit.
row
type
Array.<PrimitiveType>
An array of the underlying data from the row.
key
type
Array.<PrimitiveType>
The row index tuple (ordered list of index sets values).
details
Returns:
returns table
Type Description
type
Result
The validation result as a validation object.
Example
examples
function array1Validation(value, row, key) {
    var array2value = row[1];
    var result = new insight.validation.Result(true);
    if(value < 100 && array2value === 'STRICT') {
        result.isValid = false;
        result.errorMessage = 'Must be less that 100 if corresponding Array2 is set to STRICT';
    }
    // Build up a insight.validation.Result object with the validation outcome
    return result;
}

var table = new insight.components.AutoTable({
     tableId: 'table-1',
     columnOptions: [
         {name: 'Array1', editorValidate: array1Validation},
         {name: 'Array2'},
     ]
 });
Back to Top
members
IndicesOptions - {
type
Object }
Configuration for each Index set column AutoTable.
details
Properties:
properties
Name Type Argument Default Description
title
type
string
optional  Custom title for the index column.
style
type
string
optional  Apply one or more css classes to the index column.
render
type
Table~RenderCallback
optional  Callback to custom render the cell. Overrides any default entity rendering.
width
type
width
optional  Specify the index column width rather than using auto width calculation.
visible
type
boolean
optional  true Show or hide the column. Defaults to visible.
sortByFormatted
type
boolean
optional  false Use formatted values for sorting. This is ignored if you supply your own render function.
filterByFormatted
type
boolean
optional  Use formatted values for filtering. This defaults to false unless the entity has a label in which case the default is true. This is ignored if you supply your own render function.
format
type
string
optional  Format string.
method
Remove ( rows )

Callback function for AutoTable-Remove. Overriding this behaviour will make it your responsibility to remove the row(s) from the AutoTable, this can be done using the DataTables API.

Parameters:
params
Name Type Argument Description
rows
type
DataTable.Api
optional  Rows to be removed from the table
details
Back to Top
method
RowCallback ( rowData ) → {boolean}

Callback function for pre- and post- Add/Remove row hooks.

Parameters:
params
Name Type Description
rowData
type
Array.<PrimitiveType>
An array of the underlying data from the row
details
Returns:
returns table
Type Description
type
boolean
false if the operation to be aborted. Ignored for postAdd and postRemove actions.
Example
examples
function preAddCallback(rowData) {
    // Don't allow a row with indices 1,2,3 to be added
    return rowData[0] !== 1 || rowData[1] !== 2 || rowData[2] !== 3;
}

function preRemoveCallback(rowData) {
    // Don't allow a row with indices 9,9,9 to be removed
    return rowData[0] !== 9 || rowData[1] !== 9 || rowData[2] !== 9;
}

function addRemoveNotify(action, rowData) {
    alert('row ' + action + '. ' + rowData.join(',');
}

var table = new insight.components.AutoTable({
     tableId: 'table-1',
     ...,
     preAdd: preAddCallback,
     preRemove: preRemoveCallback,
     postAdd: addRemoveNotify.bind(table, 'add'),
     postRemove: addRemoveNotify.bind(table, 'remove')
 });
Back to Top
method
RowFilterCallback ( rowData, indices ) → {boolean}

Callback function to filter table rows. Called for each row in the table. The return value determines whether a given row should be kept or discarded.

Parameters:
params
Name Type Description
rowData
type
Array.<PrimitiveType>
Values for all cells within the row
indices
type
Array.<PrimitiveType>
The indices of the row
details
Returns:
returns table
Type Description
type
boolean
true to keep the row, false to discard it
Example
examples
// Only show rows where data adds up to 100 or more.
function rowsGreaterEqual100(rowData, indices) {
  // Only add up the data cells, omitting the indices
  var total = rowData.slice(indices.length).reduce(function(memo, value) {
    return memo + value;
  }, 0);
  return total >= 100;
}

var table = new insight.components.AutoTable({
     tableId: 'table-1',
     ...,
     rowFilter: rowsGreaterEqual100
 });
Back to Top