# Serial number in repeater

**URL:** <https://forum.wixstudio.com/t/serial-number-in-repeater/30979>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [June 30, 2020, 2:51pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979 "2020-06-30T14:51:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![learnuntildie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/learnuntildie/32/10005_2.png) [@learnuntildie](https://forum.wixstudio.com/u/learnuntildie)\
**Post date:** [June 30, 2020, 2:51pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/1 "2020-06-30T14:51:15Z")

</div>

Hi,

How can I add serial numbers in a repeater?

Thanks.

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [June 30, 2020, 2:52pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/2 "2020-06-30T14:52:28Z")

</div>

What is a serial number?

---

<div class="post-metadata">

**Author:** ![learnuntildie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/learnuntildie/32/10005_2.png) [@learnuntildie](https://forum.wixstudio.com/u/learnuntildie)\
**Post date:** [June 30, 2020, 2:56pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/3 "2020-06-30T14:56:35Z")

</div>

Sorry, I meant sequence number. If there are ten items in the repeater each line should be numbered 1, 2, 3 etc.  
My repeater displays items from a database based on user inputs and hence the number of items changes.

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [June 30, 2020, 3:00pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/4 "2020-06-30T15:00:11Z")

</div>

Add a text element to the repeater element.  
And use this code:

```javascript
$w.onReady(() => {
    $w("#repeater1").onItemReady($i, iData, index) => {
        $i("#text1").text = (index + 1).toString();
    })
})

```

---

<div class="post-metadata">

**Author:** ![learnuntildie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/learnuntildie/32/10005_2.png) [@learnuntildie](https://forum.wixstudio.com/u/learnuntildie)\
**Post date:** [June 30, 2020, 5:28pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/5 "2020-06-30T17:28:19Z")

</div>

Awesome, it worked.

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [June 30, 2020, 5:32pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/6 "2020-06-30T17:32:27Z")

</div>

You’re welcome 🙂

---

<div class="post-metadata">

**Author:** ![anidg](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anidg/32/17070_2.png) [@anidg](https://forum.wixstudio.com/u/anidg)\
**Post date:** [August 29, 2020, 11:21am UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/7 "2020-08-29T11:21:54Z")

</div>

Thank u

---

<div class="post-metadata">

**Author:** ![girishcshekar](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/girishcshekar/32/36040_2.png) [@girishcshekar](https://forum.wixstudio.com/u/girishcshekar)\
**Post date:** [January 2, 2023, 9:15pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/8 "2023-01-02T21:15:25Z")

</div>

This should ideally work, but in my case the text element in the repeater shows the same number ‘1’ for all the repeater items, even after I have inserted this code.  
P.S. I have entered the correct repeater ID and Text element ID.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [January 2, 2023, 9:32pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/9 "2023-01-02T21:32:33Z")

</div>

Check your code…

You are sure, that you have something like this… ( **GOOD** ) !!!

```javascript
$w.onReady(() => {
   $w("#repeater1").onItemReady($item,iData,index)=>{
      $item("#text1").text = (index + 1).toString();
   });
});

```

And not something like that… (WRONG) !!!

```javascript
$w.onReady(() => {
   $w("#repeater1").onItemReady($item,iData,index)=>{
      $w("#text1").text = (index + 1).toString();
   });
});

```

If still not working you can try this one…

```javascript
$w.onReady(() => {
   $w("#repeater1").forEachItem($item,iData,index)=>{
      $item("#text1").text = (index + 1).toString();
   });
});

```

## But i can confirm that everything works!

How to test it?

Generate a simple REPEATER-DATA-BLOCK…

```javascript
let data = [
        {"_id": "1", "title": "xxx"},
        {"_id": "2", "title": "yyy"},
        {"_id": "3", "title": "zzz"}
    ];

```

This simply and manually generated REPEATER-data-block will represent the REPEATERS - - → ITEMS. 3 at total.

Loading the data into repeater…

```javascript
$w("#repeater1").data = data;

```

OnItemReady-Sequence of the repeater will show us the RESULTS inside -------------\> CONSOLE.

```javascript
$w("#repeater1").onItemReady(($i,iData,index) => {
    console.log((index + 1).toString());
});

```

So the provided code above seems to be totally ok!  
Since the code was generated and provided by a VELO-MASTER - → i never expected something else 😁

Oh! Forgot to show the RESULTS…

 ![](https://us1.discourse-cdn.com/wix/original/3X/6/7/673a36a21e88d56c42f1c1e121eb42682375ae95.png)  
Seems like the counter works like a charm!

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [January 2, 2023, 11:20pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/10 "2023-01-02T23:20:04Z")

</div>

Maybe you used $w instead of $i

---

<div class="post-metadata">

**Author:** ![girishcshekar](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/girishcshekar/32/36040_2.png) [@girishcshekar](https://forum.wixstudio.com/u/girishcshekar)\
**Post date:** [January 4, 2023, 7:44pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/11 "2023-01-04T19:44:10Z")

</div>

@J.D. @russian-dima  
‘Cannot find name $item’ is the error shown on hovering over the code. Similarly for itemData and index. I have checked and the element IDs are correct.

My repeater is connected to a database (collection) to display a list of all publications in academic journals. I want the displayed list to be numbered dynamically, as I plan to filter the list by YEAR of publication.

I wonder what the issue is!  
Would be great if you could help me out with this one. Thanks.

![](https://us1.discourse-cdn.com/wix/original/3X/c/8/c837f5651b7c0ee0c27271f0c04dcda0b9f04c12.png)  
P.S. I am new to Wix, so please excuse me if my issue seems silly.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [January 4, 2023, 7:54pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/12 "2023-01-04T19:54:19Z")

</div>

Find the **ERROR** …

```javascript
$w("#rep").forEachItem(($item, itemData, index)=>{...

```

Next time - → just COPY & PASTE - → to make sure, that you do not add new ----------\> SYNTAX-ERRORS into your CODE 😁

Compare it with my (J.D.'s) provided CODE —\>

```javascript
$w("#repeater1").onItemReady(($i,iData,index)=>{

```

Both used → (( and not just one → ( ← to open the forEach-method.

---

<div class="post-metadata">

**Author:** ![girishcshekar](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/girishcshekar/32/36040_2.png) [@girishcshekar](https://forum.wixstudio.com/u/girishcshekar)\
**Post date:** [January 4, 2023, 8:05pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/13 "2023-01-04T20:05:06Z")

</div>

Thanks!  
I had missed an opening parenthesis ( after forEachItem, when I directly pasted the code from earlier replies.  
The errors in the code did go away, but my numbering is still not displayed though. The text element in the repeater items still shows the default “I’m a paragraph. Click here to add your own text and edit me. It’s easy.” after running the code.  
Maybe I’m still missing something crucial. ☹

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [January 4, 2023, 8:09pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/14 "2023-01-04T20:09:08Z")

</div>

Yes you do!

1. What is the **ID** of your **TEXT-BOX-ELEMENT**?
2. Did you implement the TEXTBOX inside your code?

```javascript
$item("#text1").text = (index+1).toString();

```

1. Is your TEXTBOX inside the —\> REPEATER ?
2. Or maybe → OUTSIDE of REPEATER ?

---

<div class="post-metadata">

**Author:** ![girishcshekar](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/girishcshekar/32/36040_2.png) [@girishcshekar](https://forum.wixstudio.com/u/girishcshekar)\
**Post date:** [January 4, 2023, 8:12pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/15 "2023-01-04T20:12:49Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/3/7/375a66bbab465bd1ca04e275e6841e85c100de67.png)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [January 4, 2023, 8:14pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/16 "2023-01-04T20:14:52Z")

</div>

How do you load the items into your repeater?  
There is no code for it!

I assume you are using → DATASET ?

---

<div class="post-metadata">

**Author:** ![girishcshekar](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/girishcshekar/32/36040_2.png) [@girishcshekar](https://forum.wixstudio.com/u/girishcshekar)\
**Post date:** [January 4, 2023, 8:15pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/17 "2023-01-04T20:15:50Z")

</div>

Yes, I’m using a Dataset and Connect option that comes along with the repeater.  
However, this particular textbox I have not connected to any field in the dataset, though being inside the repeater.

Does the numbering code not work if DATASET is used? I’m not aware.  
Can you suggest a possible solution please.

---

<div class="post-metadata">

**Author:** ![girishcshekar](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/girishcshekar/32/36040_2.png) [@girishcshekar](https://forum.wixstudio.com/u/girishcshekar)\
**Post date:** [January 4, 2023, 8:49pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/18 "2023-01-04T20:49:50Z")

</div>

I now used onItemReady instead of forEachItem and IT WORKED!!  
Thank you so much @russian-dima for the timely help.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [January 4, 2023, 8:50pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/19 "2023-01-04T20:50:04Z")

</div>

Everytime the same mistakes 😅 (again and again and again) !!!

Never try to mix working on the PROPERTIES-PANEL of a DATASET and mix them with CODE - →   
**!!! THIS WILL END IN CHAOS —\> ESPECIALLY IF YOU ARE A BEGINNER !!!**

**Surely a solution can be found for every issue, but this solution will be very tricky. At the end just GO THE CODING WAY and do not use PROPERTY-PANEL of the DATASET.**

**Working with DATASET by using settings inside DATASET’s.PROPERTY-PANEL you will face - - → BOUNDARIES.**

**To remove such boundaries at the end you will start to use code and for sure wix-data-api.**

**So everythign ends like always → You will have to start from beginning and generating all by code, if you need a specific function.**

**All examples above —\> DO NOT USE —\> DATASET !!!**

**If one the shown examples would use a dataset, you would see something like this inside the example-code…**

```javascript
$w('#dataset1').onReady(()=>{..............});

```

But if you still want to go the MIXED-VERSION…

FIRST-STEP:

1. After your dataset is READY → get all items of your dataset…

```javascript

let firstItemIndex = 0; //<--define first index
let numberOfItems = 20; //<--define number of items (dynamically) here

$w.onReady(()=> {
  $w("#dataset1").onReady( () => {
    $w("#dataset1").getItems(firstItemIndex, numberOfItems)
      .then((result) => {
        let items = result.items;
        let totalCount = result.totalCount;
        let offset = result.offset;
      })
      .catch((err) => {
        let errMsg = err.message;
        let errCode = err.code;
      });
   });
});

```

So now you are ready to load your repeater manually again, after your repeater was already loaded automatically by the dataset-connection.  
You need the second REPEATER-RELOAD, to be able to use the automated INDEXING…

```javascript
let firstItemIndex = 0;
let numberOfItems = 20;

$w.onReady( () => {
  $w("#dataset1").onReady( () => {
    $w("#dataset1").getItems(firstItemIndex, numberOfItems)
      .then((result) => {
        $w("#repeater1").data = [];
        let items = result.items;
        let totalCount = result.totalCount;
        let offset = result.offset;
        $w("#repeater1").data = items;        
      });
      .catch( (err) => {
        let errMsg = err.message;
        let errCode = err.code;
      });
  });
  
  $w("#repeater1").onItemReady($i,iData,i)=>{
    $i("#text27").text=(i+1).toString();
  });        
});

```

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [January 4, 2023, 8:51pm UTC](https://forum.wixstudio.com/t/serial-number-in-repeater/30979/20 "2023-01-04T20:51:20Z")

</div>

Pay attention when the repeater is ready!

But good to know that it worked.

EDIT:  
I did not test my version, maybe you can test it aswell, just curious to know end-result.
