cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PriyaShetty
Helper I
Helper I

How to access previous row of a gallery on button click

Hello Powerapps Users!!!!

 

I need a help on How I can access the previous row of a gallery on button click and display its data in another gallery.Images attached for clear understanding.I have used Sql  as a Datasource.

In the image Left side is a Gallery where in when i click "Prev" button prev row should be selected and its data must be displayed in right side gallery.

1 ACCEPTED SOLUTION

Accepted Solutions

Ok. I'll try to go by the basis here.

With the info you provided I cannot guess what is going on with the code of your app. However, lets try fix this from scratch.

 

The gallery you have on the left side of the screen has an Items property in which you specified the items that will be displayed in that gallery. These items you specified must have been defined within this Items property, or within a collection in another part of the app, or within the data source in particular:

 

  1. If they are defined just there in the Items property of that gallery, then just ad an id field in each record with a number in the order you want those items to be displayed.
  2. If the items are not defined within the gallery Items  property and instead, this property is filled with a collection. Go to the object/line of code where this collection is being defined and do the same. Just ad an id field with the consecutive integers you want the order of the items to be.
  3. If the Items property is filled directly with a table from your data source, just add this id on your data source or with the AddColumns function, however this is not suitable as it is going to be more complicated.

If the Items of the gallery are defined within the Items  property of the gallery or in a collection in another part of the app, they are going to be defined almost certainly in a way like this:

/* If in Items property*/

Table(
      {fieldname: "Introduction",field1:<placeholder>,field2:<placeholder>,..,fieldN:<placeholder>},
      {fieldname: "Field name 2",field1:<placeholder>,field2:<placeholder>,..,fieldN:<placeholder>}
.
.
.
      )

/* If in a collection*/

ClearCollect(
         _CollectionName,
        Table(
               {fieldname: "Introduction",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
               <placeholder>},
               {fieldname: "Field name 2",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
               <placeholder>}
               .
               .
               .
              )
)

 

In both cases, just add a field id with the numbers in the order you want them to be displayed in the gallery:

Table(
     {id:1, fieldname: "Introduction",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
     <placeholder>},
     {id:2 fieldname: "Field name 2",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
     <placeholder>},
.
.
.
)

Then just write the code I told you before in the buttons.

View solution in original post

5 REPLIES 5
jlindstrom
Super User
Super User

See @jvanrossum solution in this post —it does exactly what you are looking for https://microsoft-bitools.blogspot.com/2020/03/power-apps-get-next-item-from-gallery.html?m=1

 

FernandoTC
Resolver II
Resolver II

Hi @PriyaShetty 

There is no command to select previous item in a gallery directly. However, you can do some work-arounds.

 

In the gallery you have on the left side of the screen displaying the items "Initiation, Test Plan & Strategy, Estimation, Release", you can add (if there is no one yet) an incremental integer id and sort the gallery by this field as follows (I will call this collection as _Menu for the sake of simplicity):

{id:1, field1:"Inititation", field2:...},
{id:2, field1:"Test Plan & Strategy", field2:...},
{id:3, field1:"Estimation", field2:...},
{id:4, field1:"Release", field2:...}​


When you click "Prev" button (OnSelect property), you should set a context which I will call _selRecord as:

UpdateContext({_selRecord: Lookup(_Menu,id=_selRecord.id-1)})​

This way you are selecting the previous record of the left gallery.


Then you only have to set the right gallery property to display _selRecord. You can do the same with next button but adding 1 to that id. You will need some conditionals to avoid trying to go to an item with no existing id (going to item with id:0 or id:5 in this particular example)

You can also use this formula to define _selRecord:

UpdateContext({_selRecord: Last(Sort(Filter(_Menu,id<_selRecord.id),id,ascending)})

 This way you will always select the previous item and your id do not need to be consecutive integers, althought they need to be sorted anyways.

Hope placeholder names do not mess with the clarity of the solution.

Let me know if you need more help



Hi @FernandoTC 

Can you be clear on how can i create a colllection with fields Id and values displayed on the gallery as it is dynamic .how can i add all values to collection and have auto incremented id to it.?

Ok. I'll try to go by the basis here.

With the info you provided I cannot guess what is going on with the code of your app. However, lets try fix this from scratch.

 

The gallery you have on the left side of the screen has an Items property in which you specified the items that will be displayed in that gallery. These items you specified must have been defined within this Items property, or within a collection in another part of the app, or within the data source in particular:

 

  1. If they are defined just there in the Items property of that gallery, then just ad an id field in each record with a number in the order you want those items to be displayed.
  2. If the items are not defined within the gallery Items  property and instead, this property is filled with a collection. Go to the object/line of code where this collection is being defined and do the same. Just ad an id field with the consecutive integers you want the order of the items to be.
  3. If the Items property is filled directly with a table from your data source, just add this id on your data source or with the AddColumns function, however this is not suitable as it is going to be more complicated.

If the Items of the gallery are defined within the Items  property of the gallery or in a collection in another part of the app, they are going to be defined almost certainly in a way like this:

/* If in Items property*/

Table(
      {fieldname: "Introduction",field1:<placeholder>,field2:<placeholder>,..,fieldN:<placeholder>},
      {fieldname: "Field name 2",field1:<placeholder>,field2:<placeholder>,..,fieldN:<placeholder>}
.
.
.
      )

/* If in a collection*/

ClearCollect(
         _CollectionName,
        Table(
               {fieldname: "Introduction",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
               <placeholder>},
               {fieldname: "Field name 2",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
               <placeholder>}
               .
               .
               .
              )
)

 

In both cases, just add a field id with the numbers in the order you want them to be displayed in the gallery:

Table(
     {id:1, fieldname: "Introduction",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
     <placeholder>},
     {id:2 fieldname: "Field name 2",field1:<placeholder>,field2:<placeholder>,..,fieldN: 
     <placeholder>},
.
.
.
)

Then just write the code I told you before in the buttons.

View solution in original post

@FernandoTC  your detailed explaination is apreciated.But The items property is data from datasource directly.Also there is no id as it is a view table.Will there be any soulution to it.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,810)