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### multiSelectReturns trueifthis foundset is in multiselect mode and falseif 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, theiterationoverthefoundsetwillbestopped\.**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) Objectthereturnvalueofthecallback**Sample**```jsfoundset.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
Functioncallback 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.
ObjectthisObject 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.
//gets the current record index in the current foundsetvar current =foundset.getSelectedIndex();//sets the next record in the foundsetfoundset.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.
// modify selection to the first selected item and the following row onlyvar current =foundset.getSelectedIndexes();if (current.length>1){var newSelection =newArray(); newSelection[0] = current[0]; // first current selection newSelection[1] = current[0] +1; // and the next rowfoundset.setSelectedIndexes(newSelection);}
//gets the current record index in the current foundsetvar current =foundset.getSelectedIndex();//sets the next record in the foundsetfoundset.setSelectedIndex(current+1);
// modify selection to the first selected item and the following row onlyvar current =foundset.getSelectedIndexes();if (current.length>1){var newSelection =newArray(); newSelection[0] = current[0]; // first current selection newSelection[1] = current[0] +1; // and the next rowfoundset.setSelectedIndexes(newSelection);}