Search.../

setCurrentItemIndex( )

Sets the current item by index.

Description

The setCurrentItemIndex() function returns a Promise that is resolved when:

  • The current item has been saved in the collection (if necessary).
  • The current item has been updated to be the item with the given index.
  • Any connected page elements have been updated with the new current item’s values.

Calling setCurrentItemIndex() on a write-only dataset causes the Promise to reject.

Notes:

  • A dataset needs to load its data before you call its setCurrentItemIndex() function.

    Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you call setCurrentItemIndex() inside the page’s onReady() event handler, the dataset might not be ready yet.

    To call setCurrentItemIndex() as soon as possible after a page loads, use the dataset's onReady() function inside the page’s onReady() event handler to ensure that both the page and the dataset have finished loading.

  • When using a read-write dataset and linked input elements, calling any of the following functions will save any changes made in the linked input elements.

  • setCurrentItemIndex() saves the current item even if the requested item is same as the current item.

Syntax

function setCurrentItemIndex(index: number): Promise<void>

setCurrentItemIndex Parameters

NAME
TYPE
DESCRIPTION
index
number

The index of the item to set as the current item.

Returns

Fulfilled - When the item with the given index is set to the current item. Rejected - Rejects if the item with the given index does not exist or it cannot be set to the current item.

Return Type:

Promise<void>

Was this helpful?

Set the dataset's current item

Copy Code
1$w("#myDataset").setCurrentItemIndex(3);
Set the dataset's current item when the page loads

Copy Code
1$w.onReady( () => {
2 $w("#myDataset").onReady( () => {
3 $w("#myDataset").setCurrentItemIndex(3)
4 .then( () => {
5 console.log("Done setting current item");
6 } );
7
8 } );
9
10} );