Caplin Trader 4.7.1

Class: module:caplin/grid/GridColumnModel

module:caplin/grid/GridColumnModel

The GridColumnModel is one of the two models that are used within a grid assembly — the other being the module:caplin/grid/GridRowModel. The column model allows the currently displayed columns within a grid to be accessed and/or modified, including the addition & removal of columns, the setting of sort orders on columns, and the addition of display filters on columns.

Additionally, the column model allows classes to subscribe to column model level events. Classes that need to listen to column model events must implement the module:caplin/grid/GridColumnModelListener interface, and register themselves for these events by calling module:caplin/grid/GridColumnModel#addColumnModelListener.

Constructor

new module:caplin/grid/GridColumnModel()

Constructs a caplin.grid.GridColumnModel instance — end-users will never need to do this themselves since grids are fully constructed based on their XML definition files by the module:caplin/grid/GridComponentFactory class.

Methods

addColumnModelListener(columnModelListener)

Adds a column model listener that wishes to observe events fired from this GridColumnModel.
Parameters:
Name Type Description
columnModelListener module:caplin/grid/GridColumnModelListener The listener to add.
See:
Throws:
If the specified column model listener is not an instance of module:caplin/grid/GridColumnModelListener.
Type
module:br/Errors.InvalidParametersError

addColumns(columnIdentifiers, startIndex) → {Array}

Adds a set of columns to the GridColumnModel that will be inserted at the specified start index.

If any of the specified columns are duplicates, or if any of the specified columns are already present in the model, an array of the columns that could not be added the the model will be returned.

Parameters:
Name Type Description
columnIdentifiers Array The unique identifiers of the columns to be added to the model.
startIndex int The zero-based start index where the columns should be added.
See:
Throws:
If any column is not an instance of module:caplin/grid/GridColumn, or if the position is not within the bounds of the current columns within the model.
Type
module:br/Errors.InvalidParametersError
Returns:
Any columns that could not be added to the model.
Type
Array

applyFilters()

Applies all the filters that have been added to the columns within this GridColumnModel.

Filters can be added one at a time, and the view will need to constantly reflect the latest state of the model, and so the module:caplin/grid/GridColumnModelListener#onFiltersChanged callback method will need to fire as each change happens, whereas the application of filters so that it affects the module:caplin/grid/GridDataProvider responsible for fetching the data may not happen until some later point, depending on how the module:caplin/grid/decorator/GridDecorator instance(s) used to add these filters have been implemented.

See:

clearAllFilters()

Removes all the filters that have been added to the columns within this GridColumnModel.
See:

clearSort()

Removes any sort currently applied to the grid column model.

getActiveColumns()

Returns the list of visible columns.

Columns that are not shown, but that are available to be added, are in a separate list that can be accessed via module:caplin/grid/GridColumnModel#getAvailableColumns. When a column is added to list of active columns (using module:caplin/grid/GridColumnModel#addColumns it is at the same time removed from the list of available columns. Equally, when a column, or columns, are removed from the list of available columns (using module:caplin/grid/GridColumnModel#removeColumns) they are at the same time added to list of available columns.

getActiveFilters() → {Array}

Returns an array of all the currently active column filters.
Returns:
An array of module:caplin/grid/GridColumnFilter instances
Type
Array

getAvailableColumns()

Returns the list of columns that are not currently being shown, but are available for addition.
See:

getColumnById(columnId) → {module:caplin/grid/GridColumn}

Returns the column with specified column identifier.
Parameters:
Name Type Description
columnId String the identifier of the column as specified within the XML file used to configure the grid.
Returns:
a grid column if one exists with the given name, or null otherwise.
Type
module:caplin/grid/GridColumn

getColumnByIndex(columnIndex) → {module:caplin/grid/GridColumn}

Returns the column identified by the specified column index. Note - this index is into the currently active (visible) columns.
Parameters:
Name Type Description
columnIndex int the zero based index of the column in the currently active columns.
Returns:
a grid column if one exists with the given index in the active view, or null otherwise.
Type
module:caplin/grid/GridColumn

getRequiredFields()

Returns the list of fields the data provider must make available so that the columns have all the necesarry information to perform updates.

getSortColumn() → {module:caplin/grid/GridColumn}

Returns the column that the grid is currently using for sorting.

A grid can only be sorted on one column. If an arbitrary GridColumn has its sort order changed, then any other column that was being used for sorting will have its sort order set to no sorting. If there is currently no sorting applied to the grid, then this method will return null.

See:
Returns:
The grid column currently being used for sorting, or null if no sorting is currently applied.
Type
module:caplin/grid/GridColumn

hasColumnOrderChanged()

Determine whether the column order has changed since the grid was first opened.

isColumnAvailable(columnId) → {boolean}

Returns true if the column id is a column that is not presently active but could be made active
Parameters:
Name Type Description
columnId String the id of the column from the XML configuration.
Returns:
Type
boolean

moveColumn(currColumnIndex, newColumnIndex)

Moves the column from its present position to a new one. To move to the the very beginning use index zero. To move to the very end use the number of columns.
Parameters:
Name Type Description
currColumnIndex int Zero based index of the column to move
newColumnIndex int Index at which the column will be placed
See:

removeColumnModelListener(columnModelListener) → {boolean}

Removes a column model listener that no longer wishes to observe events fired from this GridColumnModel.
Parameters:
Name Type Description
columnModelListener module:caplin/grid/GridColumnModelListener The listener to remove.
See:
Returns:
true if the listener previously existed, and false otherwise.
Type
boolean

removeColumns(startIndex, columnCount)

Removes a set of columns from the GridColumnModel.
Parameters:
Name Type Description
startIndex int The zero-based index of the first column to be removed.
columnCount int The number of columns to remove after the start index.
See:
Throws:
If the index is not within the bounds of the current columns within the model.
Type
module:br/Errors.InvalidParametersError

replaceColumn(columnIndex, columnId)

Replaces the column at the specified index with the specified column.
Parameters:
Name Type Description
columnIndex int The index of the column to replace.
columnId String The unique identifier of the new column that will replace the existing column at the given index.
See:
Throws:
If the column is not an instance of module:caplin/grid/GridColumn, or if the position is not within the bounds of the current columns within the model.
Type
module:br/Errors.InvalidParametersError