getCurrentItemIndex( )
Returns the current item's index.
Description
The getCurrentItemIndex()
function returns the index of current item
within the items of the dataset. The indices of the items in a dataset
are zero-based. For example, if the third item is the current item, then
getCurrentItemIndex()
returns 2
.
Calling getCurrentItemIndex()
on a write-only dataset causes an error.
Returns null
if one of the following is true if the dataset:
- Is filtered to not match any items in the collection.
- Is empty.
- Has not loaded yet.
Note:
A dataset needs to load its data before you call its
getCurrentItemIndex()
function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you callgetCurrentItemIndex()
inside the page’sonReady()
event handler, the dataset might not be ready yet.To call
getCurrentItemIndex()
as soon as possible after a page loads, use the dataset'sonReady()
function inside the page’sonReady()
event handler to ensure that both the page and the dataset have finished loading.If the current item is changed from a non-dataset source, such as by selecting a row in a table connected to a dataset or clicking a button set to advance to the next item in a dataset, the dataset's current item is not updated immediately. Therefore, to get the dataset's new current item index, call
getCurrentItemIndex()
in the dataset'sonCurrentIndexChanged()
event handler. Do not use the events of the non-dataset source, such asonRowSelect
oronClick
, to callgetCurrentItemIndex()
because they will fire before the dataset's current item is updated.
Syntax
function getCurrentItemIndex(): number
getCurrentItemIndex Parameters
This function does not take any parameters.
Returns
The index of the current item, or null if there is no current item.
Return Type:
Related Content:
Was this helpful?
Get the current item's index
1let itemIndex = $w("#myDataset").getCurrentItemIndex(); // 3