# Flow script to add 'previous' and 'next' buttons to a data grid in a user step

**URL:** <https://forum.novacura.com/t/flow-script-to-add-previous-and-next-buttons-to-a-data-grid-in-a-user-step/367>\
**Category:** Flow Classic\
**Created:** [January 5, 2023, 10:35am UTC](https://forum.novacura.com/t/flow-script-to-add-previous-and-next-buttons-to-a-data-grid-in-a-user-step/367 "2023-01-05T10:35:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alyazia](https://avatars.discourse-cdn.com/v4/letter/a/7C9FD7/32.png) [@alyazia](https://forum.novacura.com/u/alyazia)\
**Post date:** [January 5, 2023, 10:35am UTC](https://forum.novacura.com/t/flow-script-to-add-previous-and-next-buttons-to-a-data-grid-in-a-user-step/367/1 "2023-01-05T10:35:55Z")

</div>

I want to make a user step with data grid have a previous/next button that would show for example 3 records per page.

I was wondering if you you can create a custom user step with a data grid and a previous/next button using the Novacura Flow scripting language.

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Jostde](https://avatars.discourse-cdn.com/v4/letter/j/7C9FD7/32.png) [@Jostde](https://forum.novacura.com/u/Jostde)\
**Post date:** [January 5, 2023, 12:03pm UTC](https://forum.novacura.com/t/flow-script-to-add-previous-and-next-buttons-to-a-data-grid-in-a-user-step/367/2 "2023-01-05T12:03:46Z")

</div>

Maybe something like this?  
The +3 should be replaced by a variable so you can choose the amount of lines displayed.  
Same goes for the 0 assigned to Startvalue.  
On Back count Startvalue - X after filtering so the next iteration will count from the new starting point on Next Startvalue + X.  
So basically execute the script step and then reset the StartValue to the “new” starting point in an assignment step after. You could also make the X a variable the user can choose himself (save it in a uservariable). In this case you should always add a Min command with 0 so you don’t go into negatives when going back.

You should also add a condition on the Back button to only show if the StartValue is \> 0. Hope this helps, let me know if you have questions.

```auto
Let counter = 0;
Let TempMyTbl = Empty(MyTbl);
Let Startvalue = 0; 

For item in MyTbl{
counter = counter +1;

If counter > Startvalue: 
Set TempMyTbl = TempMyTbl & item;

If counter >= Startvalue + 3: 
Break; 
}

Return TempMyTbl;

```

---

<div class="post-metadata">

**Author:** ![ivstde](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.novacura.com/ivstde/32/146_2.png) [@ivstde](https://forum.novacura.com/u/ivstde)\
**Post date:** [January 5, 2023, 3:35pm UTC](https://forum.novacura.com/t/flow-script-to-add-previous-and-next-buttons-to-a-data-grid-in-a-user-step/367/3 "2023-01-05T15:35:18Z")

</div>

Hi,  
you could set page number (Page) to 1, set view per page (PerPage) to somehing, then have button increasing and decreasing page number (Page) by 1 and they each go to an assignement step which filters the table (Tbl) making a new table to be shown (TblToShow) in datagrid with: TblToShow = {take(skip(Tbl,(Page-1)\*PerPage),PerPage)}

Example here:  
[Test8](https://novacura-my.sharepoint.com/:u:/p/ivan_stojiljkovic/EbC98VWJNB9Cpro66dm3rLMBtpMaWCl4p7g54sWoL1Undw?e=yj1KKZ)

Hope this helps!

B R  
Ivan

---

<div class="post-metadata">

**Author:** ![alyazia](https://avatars.discourse-cdn.com/v4/letter/a/7C9FD7/32.png) [@alyazia](https://forum.novacura.com/u/alyazia)\
**Post date:** [January 6, 2023, 8:21am UTC](https://forum.novacura.com/t/flow-script-to-add-previous-and-next-buttons-to-a-data-grid-in-a-user-step/367/4 "2023-01-06T08:21:48Z")

</div>

Thank you so much everyone 🙂 It works perfectly.
