MenuFoundSet

Overview

MenuFoundSet enables a menu structure to function as a datasource, allowing menu items to be treated as records within the Servoy Developer environment. This provides access to menu properties as dataproviders, which are read-only, and supports hierarchical relationships, such as parent-child structures based on parentid. These capabilities allow components like DBTreeView to work seamlessly with menu records and enable complex menu representations with FormComponents.

Example Usage

elements.myDbtreeview.addRoots(datasources.menu.treemenu.getFoundSet());
elements.myDbtreeview.setTextDataprovider(datasources.menu.treemenu.getDataSource(), 'menuText');
elements.myDbtreeview.setNRelationName(
  datasources.menu.treemenu.getDataSource(),
  datasources.menu.treemenu.getParentToChildrenRelationName()
);

For further details on setting up and working with datasources, see [Datasource Setup](../datasources/jsdatasource.md).


## Properties Summarized

| Type                                                  | Name                    | Summary                                                                                                           |
| ----------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| [Boolean](../js-lib/boolean.md) | [multiSelect](menufoundset.md#multiselect)                   | Returns true if this foundset is in multiselect mode and false if it's in single\-select mode\.                                    |

## Methods Summarized

| Type                                | Name                                                                                | Summary                                                             |
| ----------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| [Object](../js-lib/object.md) | [forEach\(callback\)](menufoundset.md#foreach-callback)                   | Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time\.                                    |
| [Object](../js-lib/object.md) | [forEach\(callback, thisObject\)](menufoundset.md#foreach-callback-thisobject)                   | Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time\.                                    |
| [String](../js-lib/string.md) | [getDataSource\(\)](menufoundset.md#getdatasource)                   | Returns the datasource \(menu:name\) for this MenuFoundSet\.                                    |
| [String](../js-lib/string.md) | [getName\(\)](menufoundset.md#getname)                   | Get foundset name \(menu name\)\.                                    |
| [JSRecord](./jsrecord.md) | [getRecord\(index\)](menufoundset.md#getrecord-index)                   | Get the MenuItemRecord object at the given index\.                                    |
| [Number](../js-lib/number.md) | [getRecordIndex\(record\)](menufoundset.md#getrecordindex-record)                   | Get the record index\.                                    |
| [Number](../js-lib/number.md) | [getSelectedIndex\(\)](menufoundset.md#getselectedindex)                   | Get the current record index of the foundset\.                                    |
| [Array](../js-lib/array.md) | [getSelectedIndexes\(\)](menufoundset.md#getselectedindexes)                   | Get the indexes of the selected records\.                                    |
| [JSRecord](./jsrecord.md) | [getSelectedRecord\(\)](menufoundset.md#getselectedrecord)                   |                                     |
| [Array](../js-lib/array.md) | [getSelectedRecords\(\)](menufoundset.md#getselectedrecords)                   | Get the selected records\.                                    |
| [Number](../js-lib/number.md) | [getSize\(\)](menufoundset.md#getsize)                   | Get the number of records in this menu foundset\.                                    |
| void | [setSelectedIndex\(index\)](menufoundset.md#setselectedindex-index)                   | Set the current record index\.                                    |
| void | [setSelectedIndexes\(indexes\)](menufoundset.md#setselectedindexes-indexes)                   | 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](../js-lib/boolean.md) 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](../js-lib/function.md) **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](../js-lib/object.md) Object the return value of the callback

**Sample**

```js
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()

Returns the datasource (menu:name) for this MenuFoundSet.

Returns: String

Sample

solutionModel.getForm("x").dataSource  = menuFoundSet.getDataSource();

getName()

Get foundset name (menu name).

Returns: String name.

Sample

var name = foundset.getName()

getRecord(index)

Get the MenuItemRecord object at the given index. Argument "index" is 1 based (so first record is 1).

Parameters

  • Number index record index (1 based).

Returns: JSRecord MenuItemRecord record.

Sample

var record = vfs.getRecord(index);

getRecordIndex(record)

Get the record index. Will return -1 if the record can't be found.

Parameters

Returns: Number int index.

Sample

var index = foundset.getRecordIndex(record);

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);
}

getSelectedRecord()

Returns: JSRecord

getSelectedRecords()

Get the selected records. When the menu foundset is in multiSelect mode (see property multiSelect), selection can be a more than 1 record.

Returns: Array Array current records.

Sample

var selectedRecords = foundset.getSelectedRecords();

getSize()

Get the number of records in this menu foundset. All records are loaded when foundset is initialized.

Returns: Number int current size.

Sample

var nrRecords = vfs.getSize()

for (var i = 1; i <= foundset.getSize(); i++)
{
	var rec = vfs.getRecord(i);
}

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