Interface
caplin.grid

GridDataProviderListener

This interface is implemented by the caplin.grid.DataProviderRowModel so that caplin.grid.GridDataProvider instances are able to communicate data changes as they occur. caplin.grid.GridDataProvider instances are given a reference to any listeners that may be interested in these events via the caplin.grid.GridDataProvider#addDataProviderListener method.

Constructor Summary

Attributes Name and Description
caplin.grid.GridDataProviderListener()

Method Summary

Attributes Name and Description
void onDataReceived()

This callback is invoked when requested data is first received - before any calls to #onRecordAdded, #onRecordMoved or #onSizeChanged or #onStructureChangeComplete are called.

void onDataRequested()

This callback is invoked when a request for a data has been initiated (but not a window-adjusting request)

void onDataUnavailable(String sReason)

This callback is invoked when a request for data fails.

void onRecordAdded(String sRecordId, int nIndex, Map mRecord, String sAlternateId)

Callback that occurs when one or more of the visible records are replaced by new records and need to be completely redrawn.

void onRecordContentsChanged(String sRecordId, Map mRecordUpdates)

Callback that occurs when there are updates to one or more of the visible records.

void onRecordMoved(String sRecordId, int nIndex)

Callback that occurs when a visible record is moved to a new location, and remains visible within the current page.

void onRecordRemoved(String sRecordId)

Callback that occurs when a visible record is removed/deleted.

void onSizeChanged(int nNewSize, int nOldSize)

Callback that occurs when the number of underlying records available changes.

void onStartIndexChanged(int nNewStartIndex)

Callback that occurs when, for some reason, the data provider wishes to change the start index that the view is currently looking at.

void onStructureChangeComplete()

Callback that occurs after a number of invocations to #onRecordAdded, #onRecordMoved or #onSizeChanged have been made, informing the caplin.grid.DataProviderRowModel, and underlying caplin.grid.GridView that all updates can now be rendered.

Constructor Detail

caplin.grid.GridDataProviderListener()

Method Detail

void onDataReceived()

This callback is invoked when requested data is first received - before any calls to #onRecordAdded, #onRecordMoved or #onSizeChanged or #onStructureChangeComplete are called.

void onDataRequested()

This callback is invoked when a request for a data has been initiated (but not a window-adjusting request)

void onDataUnavailable(String sReason)

This callback is invoked when a request for data fails.

Parameters
String sReason A brief description of what the error is. The enumeration caplin.grid.RowDataUnavailable provides a list of the possible values.

void onRecordAdded(String sRecordId, int nIndex, Map mRecord, String sAlternateId)

Callback that occurs when one or more of the visible records are replaced by new records and need to be completely redrawn.

This may happen because the user has scrolled the grid display causing different records to be displayed at the old indices, or when the underlying data changes, such that records are inserted, deleted or removed. When caplin.grid.GridDataProvider#PAGING is in use then only records within the range defined by caplin.grid.GridDataProvider#setRowRange are reported on.

Parameters
String sRecordId the unique identifier that the caplin.grid.GridDataProvider is using to track the records that it reports on.
int nIndex The row index at which the record exists.
Map mRecord The map of name value/pairs that contain the record data.
String sAlternateId Alternate Identifier (Deprecated, as there is no known need for an alternate id)

void onRecordContentsChanged(String sRecordId, Map mRecordUpdates)

Callback that occurs when there are updates to one or more of the visible records.

Parameters
String sRecordId the unique identifier that the caplin.grid.GridDataProvider is using to track the records that it reports on.
Map mRecordUpdates a map containing the updated field data.

void onRecordMoved(String sRecordId, int nIndex)

Callback that occurs when a visible record is moved to a new location, and remains visible within the current page.

If a record moves out of view, then the data provider does not need to perform any action, since that record will either be overwritten by some other #onRecordAdded or #onRecordMoved invocation, or will be effectively removed by an #onSizeChanged invocation with a smaller size that means that some of the previous row indices no longer exist at all.

Parameters
String sRecordId the unique identifier that the caplin.grid.GridDataProvider is using to track the records that it reports on.
int nIndex The row index at which the record will now exist.

void onRecordRemoved(String sRecordId)

Callback that occurs when a visible record is removed/deleted.

If a record is deleted from the source of the data provider's data then calling this should clean up any reference to the now defunct row.

Parameters
String sRecordId the unique identifier that the caplin.grid.GridDataProvider is using to track the records that it reports on.

void onSizeChanged(int nNewSize, int nOldSize)

Callback that occurs when the number of underlying records available changes.

This has no relation to the number of records that are being displayed, and is only a measure of the available records.

Parameters
int nNewSize the total number of available records.
int nOldSize the previous total number of available records.

void onStartIndexChanged(int nNewStartIndex)

Callback that occurs when, for some reason, the data provider wishes to change the start index that the view is currently looking at.

This event allows the data provider to adjust the start index that the view has previously set using caplin.grid.GridDataProvider#setRowRange. There are a number of reasons a data provider might wish to do this:

  1. The number of available records is updated to be smaller than the currently displayed start index, meaning that the view would otherwise now display zero records.
  2. The user wishes to track the current record they are looking at as new records appear at the top of the list.
  3. If the user is already scrolled to the top, then they wish to stay at the top even when new records appear above the previous top one.
  4. If the user is already scrolled to the bottom, then they wish to stay at the bottom even when new records appear below the previous bottom one.

All of these scrolling strategies could be, and probably should be, implemented within the caplin.grid.DataProviderRowModel, but for the purposes of efficiency it is also useful to allow them to be implemented directly within data provider, since this allows the number of round trips for data to be reduced.

Parameters
int nNewStartIndex

void onStructureChangeComplete()

Callback that occurs after a number of invocations to #onRecordAdded, #onRecordMoved or #onSizeChanged have been made, informing the caplin.grid.DataProviderRowModel, and underlying caplin.grid.GridView that all updates can now be rendered.

Allowing updates to be batched like this allows the caplin.grid.GridView class to perform more efficiently since it is able to use a single call to innerHTML to re-render a changed grid, rather than making lots of expensive, individual DOM calls.