Table
Method summary
name | description |
---|---|
addRows | Add new row to the table using specified data. |
destroy | Destroy the Table instance. This will destroy the underlying DataTable and remove the table DOM elements. |
draw | Draw the table. |
getRows | Get row or cell data. |
isLocked | Check if the table is locked. |
lock | Lock the table from being able to perform edit actions. |
numRows | Count number of rows in a table. |
removeRow | Remove a specified row from the table. |
setEditing | Set edit mode on or off. |
unlock | Unlock the table so that editing can resume. |
updateRow | Update a specified row or cell with new data. |
Constructor
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
configuration |
type
object |
Table configuration options Properties
params
|
Members
-
EditorType - {
typestring }
-
Enum for the table editor types that are supported.details
Properties:
propertiesName Type Default Description CHECKBOX typestringcheckbox TEXT typestringtext SELECT typestringselect -
dataTable - {
typejQuery }
-
A reference to the underlying DataTable object.details
Methods
- addRows ( data, redraw ) → {Array.<number>}
-
Add new row to the table using specified data.
Parameters:
paramsName Type Argument Default Description data typeArrayThe new row data redraw typebooleanoptional true Whether to redraw the table after adding the rows detailsReturns:returns tableType Description typeArray.<number>Array of row indexes that have been added to aoData - destroy ( )
-
Destroy the Table instance. This will destroy the underlying DataTable and remove the table DOM elements.
details - draw ( )
-
Draw the table.
details - getRows ( row, col ) → {Object|string}
-
Get row or cell data.
Parameters:
paramsName Type Argument Description row typejQuery | numberTR row node, TD/TH cell node or the row index col typenumberoptional Column index. If not given then the function will return the entire row detailsReturns:returns tableType Description typeObject | stringEither data for entire row or, if col is specified, data for the specified cell - isLocked ( ) → {boolean}
-
Check if the table is locked.
detailsReturns:returns tableType Description typebooleanWhether the table is locked or not - lock ( overlayMessage )
-
Lock the table from being able to perform edit actions.
Parameters:
paramsName Type Argument Description overlayMessage typestringoptional Provide a custom overlay message. Otherwise uses a default message. details - numRows ( ) → {number}
-
Count number of rows in a table.
detailsReturns:returns tableType Description typenumberThe number of rows present - removeRow ( row, redraw ) → {Array.<*>}
-
Remove a specified row from the table.
Parameters:
paramsName Type Argument Default Description row typenumberThe row number to delete redraw typebooleanoptional true Whether to redraw the table after adding the rows detailsReturns:returns tableType Description typeArray.<*>Data of the row that was deleted - setEditing ( enabled )
-
Set edit mode on or off.
Parameters:
paramsName Type Description enabled typebooleanWhether edit mode should be enabled details - unlock ( )
-
Unlock the table so that editing can resume.
details - updateRow ( row, col, data, redraw ) → {number}
-
Update a specified row or cell with new data.
Parameters:
paramsName Type Argument Default Description row typenumbercol typenumberdata typeArrayThe new row data redraw typebooleanoptional true Whether to redraw the table after adding the rows detailsReturns:returns tableType Description typenumber0 on success, 1 on error
Type Definitions
-
Cell - {
typeobject }
-
details
Properties:
propertiesName Type Description displayPosition typeTable#DisplayPositionThe display position of this cell rowData typeArray.<PrimitiveType>The row data value typePrimitiveTypeThe cell value element typeElementThe cell DOM Element. -
DisplayPosition - {
typeobject }
-
details
Properties:
propertiesName Type Description row typenumberrow index column typenumbercolumn index -
ColumnOptions - {
typeObject }
-
details
Properties:
propertiesName Type Argument Default Description name typestringThe title to be displayed for this column. width typestringoptional The column width. Takes any valid css value for defining width. type typeinsight.enums.DataTypeThe data type this column. Can only be one of the primitive types from Xpress Insight. This is used to determine sorting semantics. displayType typeinsight.enums.DataTypeoptional The display data type for this column. Can only be one of the primitive types from Xpress Insight. This is used for display styling. If not specified then the 'type' property will be used. visible typebooleanoptional true Show or hide the column. Defaults to visible. cellType typestringoptional 'td' Specify the type of cell to use for this column. Either 'th' or 'td'. style typestringoptional A class name to be applied to all cells in this column. render typeTable~RenderCallbackoptional A function to render each cell in this column. editable typebooleanoptional false Whether cells in this column are editable or not. editorType typeTable.EditorTypeoptional The editor type to use, in edit mode, for cells in this column. If not specified then it will be autodetected based on column data type and additional column options provided. checkedValue type*optional The value to set the cell data to if input type is checkbox and it is checked. Required if input type of checkbox is specified. uncheckedValue type*optional The value to set the cell data to if input type is checkbox and it is not checked. Required if input type of checkbox is specified. editorSelectOptions typeTable~EditorOptionsCallback | Array.<PrimitiveType> | Object.<{string, PrimitiveType}> | Array.<{key: string, value: PrimitiveType}>optional Select input options as: editor options callback to generate the options on demand, plain array (values used for both title and value), key-value object (key as title, value as select value), array of objects (key property as title, value property as select value) editorValidate typeTable~EditorValidateCallbackoptional A callback to validate each cell edit in this column. editorSave typeTable~EditorSaveCallbackoptional Called after a cell has been edited and passes validation. Can be used to perform a save action for example. -
Coordinate - {
typeObject }
-
details
Properties:
propertiesName Type Description row typenumberThe row index column typenumberThe column index - CoordinateTranslator ( coordinate ) → {Table~Coordinate}
-
Parameters:
paramsName Type Description coordinate typeTable~CoordinateThe visual coordinate detailsReturns:returns tableType Description typeTable~Coordinate - EditorOptionsCallback ( value, row ) → {Array.<PrimitiveType>|Object.<*, string>|Array.<{key: string, value: PrimitiveType}>}
-
Returns a list of editor options to display. Either an array of values to display and set or an object of keys to display values.
Parameters:
paramsName Type Description value typePrimitiveTypeCurrent value of the cell row typeArray.<PrimitiveType>Current value for all cells in the row detailsReturns:returns tableType Description typeArray.<PrimitiveType> | Object.<*, string> | Array.<{key: string, value: PrimitiveType}>The editor options Example
examples
Back to Topfunction (value, row) { var list = [ {key: '-1', value: 'None'}, {key: '1', value: 'One'}, ]; // Show extended list of options if column 2 it true if (row[1]) { list = list.concat([ {key: '2', value: 'Two'}, {key: '3', value: 'Three'} ]); } return list; },
- EditorSaveCallback ( data, row, cell ) → {Promise}
-
Callback function triggered after a cell has been edited and validated successfully.
Parameters:
paramsName Type Description data typePrimitiveTypeThe new value from the cell edit. row typeArray.<PrimitiveType>An array of the underlying data from the row. This will include the original value for the cell that was edited. cell typeElementThe cell DOM Element. detailsReturns:returns tableType Description typePromiseThe save callback is treated as asynchronous as so should return a Promise that resolves on success or is rejected on failure. Example
examples
Back to Topfunction save(columnName, data, row, cell) { // Get the index for the modified row var index = row.slice(0, 2); // Save to the server and wait for a success or failure response return new Promise(resolve, reject) { $.post('https://myhost', { column: columnName, value: data, index: index }).then(resolve, reject); }); } var table = new insight.components.Table({ id: 'table-1', columns: [ {name: 'Index1'}, {name: 'Index2'}, {name: 'Column1', editable: true, editorSave: save.bind(table, 'Column1')}, {name: 'Column2', editable: true, editorSave: save.bind(table, 'Column2')}, ], data: [...] });
- EditorValidateCallback ( data, row, cell ) → {Insight.validation.Result}
-
Callback function for cell validation.
Parameters:
paramsName Type Description data typePrimitiveTypeThe new value from the edit. row typeArray.<PrimitiveType>An array of the underlying data from the row. cell typeElementThe cell DOM Element. detailsReturns:returns tableType Description typeInsight.validation.ResultThe validation result as a validation object. Example
examples
Back to Topfunction column1Validation(value, row, cell) { var column2value = row[1]; var result = new insight.validation.Result(true); if(value < 100 && column2value === 'STRICT') { result.isValid = false; result.errorMessage = 'Must be less that 100 if corresponding Column2 is set to STRICT'; } // Build up a insight.validation.Result object with the validation outcome return result; } var table = new insight.components.Table({ id: 'table-1', columns: [ {name: 'Column1', editorValidate: column1Validation}, {name: 'Column2'}, ], data: [...] });
- PasteHandler ( cellContent, topLeft ) → {undefined}
-
Parameters:
paramsName Type Description cellContent typeArray.<Array.<string>>The string values to set, each element is a row topLeft typeTable~Coordinatecoordinates of start point in which to paste detailsReturns:returns tableType Description typeundefined - RenderCallback ( data, type, row ) → {string}
-
Callback function for custom rendering each cell in a Table column.
Parameters:
paramsName Type Description data typearray | objectThe data for the cell (based on DataTables columns.dataDT) type typestringThe type call data requested - this will be 'filter', 'display', 'type' or 'sort'. row typearray | objectThe full data source for the row (not based on DataTables columns.dataDT) detailsReturns:returns tableType Description typestringA string containing the custom text and/or HTML markup for this item. Example
examples
Back to Topfunction currencyCellFormatter(data, type, row) { // Format as US currency. Note it is up to you to html escape the display data returned when using the column render option. switch (type) { case 'display': return htmlEscape(insight.Formatter.formatNumber(data, '$#,##0.00')); case 'filter': return htmlEscape(insight.Formatter.formatNumber(data, '$0.00')); } return data; } var table = new insight.components.Table({ id: 'table-1', columns: [ {name: 'Index1'}, {name: 'Column1', render: currencyCellFormatter}, {name: 'Column2', render: currencyCellFormatter}, ], data: [...] });
- RowKeyGenerator ( data, rowPosition ) → {string}
-
Callback to generate a key for a row. This is used to find the current active row when a table is redrawn.
You will probably only want to include the fixed index cells of a row in the key and join them with a string token.
AutoTable will automatically generate a row key based on the non-filtered indices. Table, by default, will generate a row key based on all cells in the row.Parameters:
paramsName Type Description data typeArray.<PrimitiveType>Contents of each cell in the row rowPosition typenumberThe row display position detailsReturns:returns tableType Description typestringThe generated key for the row Example
examples
Back to Top// If the first 2 columns in the table are fixed, index values function generateRowKey(data, position) { return JSON.stringify(data.slice(0, 1)); }
Events
- selection-changed
-
Selection changed event. Triggered whenever the selection is changed, e.g. when user creates new selection. This event is triggered on the
table
element. Event handler also receives context of the selection, which includes selection cell list, active cell and selection type.detailsProperties:
propertiesName Type Description selection typeArray.<Table#Cell>an array of table cells representing selection activeCell typeTable#Cellcurrently active table cell selectionType typestringselection type Example
examples
Back to Top$('#table-id').on('selection-changed', function (event, context) { console.log(context.activeCell); });
- selection-removed
-
Selection removed event. Triggered whenever the selection is destroyed, e.g. when sorting and filtering. This event is triggered on the
table
element.detailsExample
examples
Back to Top$('#table-id').on('selection-removed', function (event) { console.log(event.type); });