Class: HTMLTableWrapperListener

HTMLTableWrapperListener(table, columnControlFactoryopt, cellInterpreteropt)

Facilitates communication between the API-level HTMLTableWrapper and the UI-level ColumnControl. In addition to the constraints placed on the backing HTMLTableElement in HTMLTableWrapper, this class also requires it to define a table header section (<thead>) with the first row's cells defining the column headers for the table. Although the table can define more than one row in its table header section, only the first row will be processed by this class.

Upon initialization, this class will add itself as a listener for click events on all cells in the first row of the backing HTMLTableElement's table header section, as well as add the class name HTMLTableWrapperListener.processedColumnHeader to each cell.

In response to click events, the appropriate ColumnControl will be created using the given ColumnControlFactory (or HTMLTableWrapperListener~getColumnControl callback), if defined, or will fall back to HTMLTableWrapperControl in the case no ColumnControlFactory (or callback) is defined, or the call to ColumnControlFactory#getColumnControl (or direct invocation of the HTMLTableWrapperListener~getColumnControl callback) returns Nothing. ColumnControls are cached after they are created, and are reused for subsequent click events. The given cellInterpreter is used when falling back to HTMLTableWrapperControl.

ColumnControls can make calls back to HTMLTableWrapperListener#processTable to trigger table-wide sorting and filtering in response to user-triggered events on the control that would be expected to update the state of the backing table. Upon a call to HTMLTableWrapperListener#processTable, ColumnControl#getFilterDescriptor and ColumnControl#getSortDescriptor are called for each cached ColumnControl. Each result that is not Nothing is stored, and ultimately passed to HTMLTableWrapper#filter and HTMLTableWrapper#sort. (Implicit to this, calls to HTMLTableWrapperListener#processTable should not be made in ColumnControl#getFilterDescriptor and ColumnControl#getSortDescriptor, as such would cause infinite recursion).

Constructor

new HTMLTableWrapperListener(table, columnControlFactoryopt, cellInterpreteropt)

Parameters:
Name Type Attributes Description
table HTMLTableElement | HTMLTableWrapper

HTMLTableElement or HTMLTableWrapper backing this listener.

columnControlFactory ColumnControlFactory | HTMLTableWrapperListener~getColumnControl <optional>

Optional factory if custom column controls are needed.

cellInterpreter CellInterpreter | HTMLTableWrapperControl~populateCellValues <optional>

Interpreter to use when falling back to the default HTMLTableWrapperControl on calls to HTMLTableWrapperListener#getColumnControl.

Implements:
Source:

Members

(static) processedColumnHeader

Class name added to HTMLTableCellElements upon which HTMLTableWrapperListener instances are registered for click events. Default value is 'data-table-column-header'.

Source:

(private) columnControlFactory :ColumnControlFactory

ColumnControlFactory to use when creating controls.

Type:
Source:

(private) columnControls :Array.<ColumnControl>

ColumnControl cache.

Type:
Source:

(private) dataTable :HTMLTableWrapper

Backing HTMLTableWrapper.

Type:
Source:

(private) sortDescriptorOrder :Array.<number>

Current column-order in which to apply sort descriptors. Initially null, initialized on first call to HTMLTableWrapperListener#processTable.

Type:
  • Array.<number>
Source:

(private) tableHeaderCache :Array.<HTMLTableCellElement>

Cache of HTMLTableCellElements for which this class is registered for click events.

Type:
  • Array.<HTMLTableCellElement>
Source:

Methods

dispose()

Disposes this HTMLTableWrapperListener. This HTMLTableWrapperListener will remove itself as a click listener for any HTMLTableCellElements upon which it has registered itself, as well as remove the HTMLTableWrapperListener.processedColumnHeader class name. Additionally, if any cached ColumnControls define a dispose function, it will also be called.

Implements:
Source:

getColumnControl(columnIndex) → {ColumnControl}

Obtains a ColumnControl for the given columnIndex. If one is cached (has been obtained before), it will be returned. Otherwise it will be created using the ColumnControlFactory passed to the constructor of this HTMLTableWrapperListener. If defined, and its ColumnControlFactory#getColumnControl (or its direct invocation if a HTMLTableWrapperListener~getColumnControl) function returns a value that is not Nothing, that value will be cached and returned. Failing that, a new HTMLTableWrapperControl will be cached and returned.

Parameters:
Name Type Description
columnIndex number

Index of the column for which a ColumnControl is to be obtained.

Source:
Throws:

If columnIndex is greater than or equal to the number of columns in the backing table.

Type
RangeError
Returns:

The newly created, or previously cached ColumnControl for the given columnIndex.

Type
ColumnControl

getDataTable() → {HTMLTableWrapper}

Returns this HTMLTableWrapperListener's backing HTMLTableWrapper.

Source:
Returns:

This HTMLTableWrapperListener's backing HTMLTableWrapper.

Type
HTMLTableWrapper

getTableHeaderElement(columnIndex) → {HTMLTableCellElement}

Returns the HTMLTableCellElement acting as the column header for the given columnIndex.

Parameters:
Name Type Description
columnIndex number

Index of the column header to be retrieved.

Source:
Throws:

If columnIndex is greater than or equal to the number of columns in the backing table.

Type
RangeError
Returns:

The HTMLTableCellElement acting as the column header for the given columnIndex.

Type
HTMLTableCellElement

handleEvent(event)

Implementation of DOM EventListener.

Parameters:
Name Type Description
event Event

Event being dispatched.

Source:

init()

Initializes this HTMLTableWrapperListener. This HTMLTableWrapperListener will be added as a click listener for each HTMLTableCellElement in the first row of the backing table's header section. The class name HTMLTableWrapperListener.processedColumnHeader will also be added to each cell.

Implements:
Source:

openColumnControl(columnIndex)

Opens the ColumnControl for the given columnIndex. Delegates to HTMLTableWrapperListener#getColumnControl to obtain the ColumnControl to be opened. After obtained, ColumnControl#open will be called on it, and ColumnControl#close on all others in the cache.

Parameters:
Name Type Description
columnIndex number

Index of the column upon which a ColumnControl is to be opened.

Source:
Throws:

If columnIndex is greater than or equal to the number of columns in the backing table.

Type
RangeError

processTable()

Filters and sorts the backing table based upon the state of cached ColumnControls.

The ColumnControl#getFilterDescriptor and ColumnControl#getSortDescriptor functions are called for each cached ColumnControl in the order they are created. Each result that is not Nothing is stored in a distinct Array (one for FilterDescriptors, another for SortDescriptors), and subsequently passed to the backing HTMLTableWrapper's HTMLTableWrapper#filter and HTMLTableWrapper#sort functions. Filtering is performed before sorting.

SortDescriptors are ordered according to the order in which they are/were returned from this and previous calls. E.g., consider the following sequence of calls to processTable:

  1. A valid SortDescriptor is returned for column 1 => table will be ordered by column 1
  2. A valid SortDescriptor is returned for columns 1 and 2 => table will be ordered by columns 1, 2
  3. A valid SortDescriptor is returned for columns 1, 2, and 3 => table will be ordered by columns 1, 2, 3
  4. A valid SortDescriptor is only returned for columns 2 and 3 => table will be ordered by columns 2, 3
  5. A valid SortDescriptor is returned for columns 1, 2, and 3 again => table will be ordered by columns 2, 3, 1
Source:

Type Definitions

getColumnControl(columnIndex, parent) → {ColumnControl}

Called by HTMLTableWrapperListener to obtain a ColumnControl for a given column. If a value is returned, it will be used as the control for that column. If Nothing is returned, the default control (HTMLTableWrapperControl) will be created and used for that column.

Parameters:
Name Type Description
columnIndex number

Column index for which a ColumnControl is needed.

parent HTMLTableWrapperListener

The HTMLTableWrapperListener requesting a control.

Source:
Returns:

A ColumnControl if a client-defined control is needed for the given columnIndex, otherwise Nothing.

Type
ColumnControl