JSBaseFoundset

Overview

JSBaseFoundSet provides a unified interface for working with foundsets, exposing shared functionalities for regular and view foundsets. It supports key operations such as iteration, selection, and data source retrieval. The multi-select mode allows multiple records to be handled simultaneously. This abstraction ensures consistency across various foundset types.

Features

JSBaseFoundSet allows iteration over records with the forEach method, which handles dynamic loading while respecting Servoy’s lazy-loading mechanism. Callback functions can interact with records while accommodating changes like inserts and deletions. Exceptions ensure stability when the foundset is modified during iteration.

The class provides methods to retrieve details about the data source and selected records. Methods like getDataSource return the underlying data source, while getSelectedIndex and getSelectedIndexes provide details about currently selected records. The size of the cached row identifiers can be retrieved using getSize.

Selection Management

JSBaseFoundSet includes methods for managing record selection. Developers can set or retrieve the currently selected record index with setSelectedIndex and getSelectedIndex. For multi-select scenarios, setSelectedIndexes and getSelectedIndexes enable handling multiple selected records.

For more information, refer to the FoundSet documentation.

Properties Summarized

Type
Name
Summary

Returns true if this foundset is in multiselect mode and false if it's in single-select mode.

Methods Summarized

Type
Name
Summary

Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.

Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.

The datasource this foundset is build on

Get the index of a record object inside a foundset

Get the current record index of the foundset.

Get the indexes of the selected records.

Get the size of present cached row identifiers (primary keys)

void

Set the current record index.

void

Set the selected records indexes.

Properties Detailed

multiSelect

Returns true if this foundset is in multiselect mode and false if it's in single-select mode.

Type Boolean true if this foundset is in multiselect mode and false if it's in single-select mode.

Methods Detailed

forEach(callback)

Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time. It will dynamically load all records in the foundset (using Servoy lazy loading mechanism). If callback function returns a non null value the traversal will be stopped and that value is returned. If no value is returned all records of the foundset will be traversed. Foundset modifications( like sort, omit...) cannot be performed in the callback function. If foundset is modified an exception will be thrown. This exception will also happen if a refresh happens because of a rollback call for records on this datasource when iterating. When an exception is thrown from the callback function, the iteration over the foundset will be stopped.

Parameters

  • Function callback The callback function to be called for each loaded record in the foundset. Can receive three parameters: the record to be processed, the index of the record in the foundset, and the foundset that is traversed.

Returns: Object Object the return value of the callback

Sample

foundset.forEach(function(record,recordIndex,foundset) {
 	//handle the record here
 });

forEach(callback, thisObject)

Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time. It will dynamically load all records in the foundset (using Servoy lazy loading mechanism). If callback function returns a non null value the traversal will be stopped and that value is returned. If no value is returned all records of the foundset will be traversed. Foundset modifications( like sort, omit...) cannot be performed in the callback function. If foundset is modified an exception will be thrown. This exception will also happen if a refresh happens because of a rollback call for records on this datasource when iterating. When an exception is thrown from the callback function, the iteration over the foundset will be stopped.

Parameters

  • Function callback The callback function to be called for each loaded record in the foundset. Can receive three parameters: the record to be processed, the index of the record in the foundset, and the foundset that is traversed.

  • Object thisObject What the this object should be in the callback function (default it is the foundset)

Returns: Object Object the return value of the callback

Sample

foundset.forEach(function(record,recordIndex,foundset) {
 	//handle the record here
 });

getDataSource()

The datasource this foundset is build on

Returns: String the datasource

getName()

Returns: String

getRecordIndex(record)

Get the index of a record object inside a foundset

Parameters

Returns: Number the index or -1 if not present (anymore)

getSelectedIndex()

Get the current record index of the foundset.

Returns: Number int current index (1-based)

Sample

//gets the current record index in the current foundset
var current = foundset.getSelectedIndex();
//sets the next record in the foundset
foundset.setSelectedIndex(current+1);

getSelectedIndexes()

Get the indexes of the selected records. When the foundset is in multiSelect mode (see property multiSelect), a selection can consist of more than one index.

Returns: Array Array current indexes (1-based)

Sample

// modify selection to the first selected item and the following row only
var current = foundset.getSelectedIndexes();
if (current.length > 1)
{
	var newSelection = new Array();
	newSelection[0] = current[0]; // first current selection
	newSelection[1] = current[0] + 1; // and the next row
	foundset.setSelectedIndexes(newSelection);
}

getSelectedRecords()

Returns: Array

getSize()

Get the size of present cached row identifiers (primary keys)

Returns: Number the number of rows which can be received via getRecord

setSelectedIndex(index)

Set the current record index.

Parameters

  • Number index index to set (1-based)

Returns: void

Sample

//gets the current record index in the current foundset
var current = foundset.getSelectedIndex();
//sets the next record in the foundset
foundset.setSelectedIndex(current+1);

setSelectedIndexes(indexes)

Set the selected records indexes.

Parameters

  • Array indexes An array with indexes to set.

Returns: void

Sample

// modify selection to the first selected item and the following row only
var current = foundset.getSelectedIndexes();
if (current.length > 1)
{
	var newSelection = new Array();
	newSelection[0] = current[0]; // first current selection
	newSelection[1] = current[0] + 1; // and the next row
	foundset.setSelectedIndexes(newSelection);
}

Last updated