cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
richw6418
Regular Visitor

how to define the gallery item if need show multi rows of the sharepoint list

Quite new to Power Apps... I'm trying to build a calendar-like app for team events.

Basically, the SharePoint list is quite simple, a Choice column as dropdown to select the category, a date column, and a text column to add the event narratives.

richw6418_0-1599637686188.png

 

Expected Power App screen like this:

richw6418_1-1599638032119.png

 

To fulfil the purpose, how shall I set the Item for the Gallery? I thought the Gallery Item is to get a table from the list, and each item (ThisItem) is a certain row. In my case, to a certain category, the Event text are from multi rows because of the different dates.

 

Or shall it be multiple galleries to do the work? How to align the items from multiple galleries?

 

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @richw6418 :

Since your data source does not have a week column, If you want to achieve the required functions, the "item" of the "Gallery" is destined to be impossible to be the original data source.In other words, Gallery.Selected is unusable under any circumstances.

In addition, since the events of a week in the calendar are composed of multiple records, if you want to create a new event in the calendar, you should use NewFrom instead of EditFrom.

Please try:

1\Add a Gallery(Gallery1)

Items

Choices(MySPList.Category)

2\Add four labels into this gallery

Label-text

Concat(
    Filter(
        MySPList,
        Date >= start && Date < DateAdd(
            start,
            7,
            Days
        ) && Category.Value =ThisItem.Value
    ),
    Event,
    Char(13)
)

OnSelect

Select(Parent);Set(TheDate,DateAdd(
            start,
            7,
            Days
        ))

Label2-Text

Concat(
    Filter(
        MySPList,
        Date >= DateAdd(
            start,
            7,
            Days
        ) && Date < DateAdd(
            start,
            14,
            Days
        ) && Category.Value = ThisItem.Value
    ),
    Event,
    Char(13)
)

OnSelect

Select(Parent);Set(TheDate,DateAdd(
            start,
            7,
            Days
        ))

……

2\Add a New From

DataSource

MySPList

DefaultMode

FormMode.New

Set the combo box(Categroy)'s DefaultSelectedItems property to

Gallery1.Selected

 Set the Date Picker(Date)'s DefaultDate property to

TheDate

13.gif

Best Regards,

Bof

View solution in original post

8 REPLIES 8
v-bofeng-msft
Community Support
Community Support

Hi @richw6418 :

Could you tell me:

How do you define a week?

  • Whether the week start on Monday or Sunday?
  • Should the insufficient part of the week at the beginning/end of the month be filled with the dates of the adjacent months?

Does Category allow multiple selections?I assume Category do not allow multiple sellctions.

I assume that the week starts on Monday (if it is different, you can adjust my formula) and the missing part of the week at the beginning of the month and the end of the month is filled with the dates of the adjacent months.

The key is to use a combination of functions to reconstruct a new table.I've made a test for your reference:

My data source:

1.jpg

1\Set the APP's OnStart propery to:

 

Set(TheDate,Date(Year(Today()),Month(Today()),1));
Set(start,DateAdd(TheDate,-Weekday(TheDate)+2,Days));
Set(end,DateAdd(DateAdd(DateAdd(TheDate,1,Months),-1,Days),8-Weekday(DateAdd(DateAdd(TheDate,1,Months),-1,Days)),Days))

 

and then run OnStart

2.JPG

2\Add a label control and set it's Text property to:

 

Text(TheDate,"[$-en]yyyy-mm")

 

3\Add a left arrow icon and set it's OnSelect Property to:

 

Set(TheDate,DateAdd(TheDate,-1,Months));
Set(start,DateAdd(TheDate,-Weekday(TheDate)+2,Days));
Set(end,DateAdd(DateAdd(DateAdd(TheDate,1,Months),-1,Days),8-Weekday(DateAdd(DateAdd(TheDate,1,Months),-1,Days)),Days))

 

4\Add a right arrow icon and set it's OnSelect Property to:

 

Set(TheDate,DateAdd(TheDate,1,Months));
Set(start,DateAdd(TheDate,-Weekday(TheDate)+2,Days));
Set(end,DateAdd(DateAdd(DateAdd(TheDate,1,Months),-1,Days),8-Weekday(DateAdd(DateAdd(TheDate,1,Months),-1,Days)),Days))

 

5\Add a DataTable control and set it's Items Properyt to:

 

ShowColumns(
    AddColumns(
        GroupBy(
            AddColumns(
                Filter(
                    MySPList,
                    Date >= start && Date <= end
                ),
                "TheCategory",
                Category.Value
            ),
            "TheCategory",
            "MyGroup"
        ),
        "Week1",
        Concat(
            Filter(
                MyGroup,
                Date >= start && Date < DateAdd(
                    start,
                    7,
                    Days
                )
            ),
            Event,
            Char(13)
        ),
        "Week2",
        Concat(
            Filter(
                MyGroup,
                Date >= DateAdd(
                    start,
                    7,
                    Days
                ) && Date < DateAdd(
                    start,
                    14,
                    Days
                )
            ),
            Event,
            Char(13)
        ),
        "Week3",
        Concat(
            Filter(
                MyGroup,
                Date >= DateAdd(
                    start,
                    14,
                    Days
                ) && Date < DateAdd(
                    start,
                    21,
                    Days
                )
            ),
            Event,
            Char(13)
        ),
        "Week4",
        Concat(
            Filter(
                MyGroup,
                Date >= DateAdd(
                    start,
                    21,
                    Days
                ) && Date < DateAdd(
                    start,
                    28,
                    Days
                )
            ),
            Event,
            Char(13)
        ),
        "Week5",
        Concat(
            Filter(
                MyGroup,
                Date >= DateAdd(
                    start,
                    28,
                    Days
                ) && Date < DateAdd(
                    start,
                    35,
                    Days
                )
            ),
            Event,
            Char(13)
        )
    ),
    "TheCategory",
    "Week1",
    "Week2",
    "Week3",
    "Week4",
    "Week5"
)

 

 3.gif

Best Regards,

Bof

Hi @v-bofeng-msft , much appreciated for your guidance, it's quite helpful.

 

But seems I didn't clearly describe what I need... it's a table view, but for each event shown could be clicked, showing details, modifiable. Click on a blank 'cell' can add a new event. So I was thinking gallery items linking to the SharePoint list.

 

Because of the structure of the SP list/table, for each category,  there're multiple rows for different dates and different events, my brain got twisted when thinking about how to show these multi items on the screen.

 

I also tried to use GroupBy Category, however, the column was a Choice column in SP, Power Apps can't recognise the column.

 

Hi @richw6418 :

I'm afraid it is difficult to use Gallery.

I have tried to use the two-level nested Gallery. The display is normal, but the selecteditem of the sub Gallery cannot be obtained.

9.gif

I have an alternative plan for your reference:

  • Using 3*5=15 Label controls to solve this problem, and encode the Items property and OnSelect property of each Label control

For Example:

Label 1

Text

Concat(
    Filter(
        MySPList,
        Date >= start && Date < DateAdd(
            start,
            7,
            Days
        ) && Category.Value = "Category1"
    ),
    Event,
    Char(13)
)

Label2

Concat(
    Filter(
        MySPList,
        Date >= DateAdd(
            start,
            7,
            Days
        ) && Date < DateAdd(
            start,
            14,
            Days
        ) && Category.Value = "Category1"
    ),
    Event,
    Char(13)
)

……

Best Regards,

Bof

Hi @richw6418 :

Maybe you don’t need a gallery with a nested structure.

1\Add a Gallery

Items

Choices(MySPList.Category)

2\Add four labels into this gallery

Label-text

Concat(
    Filter(
        MySPList,
        Date >= start && Date < DateAdd(
            start,
            7,
            Days
        ) && Category.Value =ThisItem.Value
    ),
    Event,
    Char(13)
)

Label2-Text

Concat(
    Filter(
        MySPList,
        Date >= DateAdd(
            start,
            7,
            Days
        ) && Date < DateAdd(
            start,
            14,
            Days
        ) && Category.Value = ThisItem.Value
    ),
    Event,
    Char(13)
)

……

Best Regards,

Bof

 

Hi @v-bofeng-msft ,

Your way worked perfectly for displaying the Category, Week, and the associated Event. Thanks a lot.

 

Using Choices to select the unique Category value is good, however, the Gallery Item is then linked to the Category column, rather than the SP List. Thus seems I can't use Gallery.Selected for EditForm, which suppose link to the data source - SP List.

 

With this approach, how shall I add/edit Event for a certain item by selecting the text labels, then update to the data source?

 

Much appreciated.

Hi @richw6418 :

Since your data source does not have a week column, If you want to achieve the required functions, the "item" of the "Gallery" is destined to be impossible to be the original data source.In other words, Gallery.Selected is unusable under any circumstances.

In addition, since the events of a week in the calendar are composed of multiple records, if you want to create a new event in the calendar, you should use NewFrom instead of EditFrom.

Please try:

1\Add a Gallery(Gallery1)

Items

Choices(MySPList.Category)

2\Add four labels into this gallery

Label-text

Concat(
    Filter(
        MySPList,
        Date >= start && Date < DateAdd(
            start,
            7,
            Days
        ) && Category.Value =ThisItem.Value
    ),
    Event,
    Char(13)
)

OnSelect

Select(Parent);Set(TheDate,DateAdd(
            start,
            7,
            Days
        ))

Label2-Text

Concat(
    Filter(
        MySPList,
        Date >= DateAdd(
            start,
            7,
            Days
        ) && Date < DateAdd(
            start,
            14,
            Days
        ) && Category.Value = ThisItem.Value
    ),
    Event,
    Char(13)
)

OnSelect

Select(Parent);Set(TheDate,DateAdd(
            start,
            7,
            Days
        ))

……

2\Add a New From

DataSource

MySPList

DefaultMode

FormMode.New

Set the combo box(Categroy)'s DefaultSelectedItems property to

Gallery1.Selected

 Set the Date Picker(Date)'s DefaultDate property to

TheDate

13.gif

Best Regards,

Bof

View solution in original post

Thanks a lot for the guidance from @v-bofeng-msft , with the help, I updated my App not trying to use Gallery.Selected to directly link to the SharePoint list items, but to use it for filtering purpose.

 

Summarised for myself about how I followed the instruction to get it done... 

 

richw6418_0-1600390826655.png

When click on the Text Label of the Event, will set a variable to store the week end date associated to this label, which will be used in the EditForm. The Form uses ShowDetail in Visible property to show like pop-up. If the label is blank, which means there's no record yet, will use NewForm() changing mode to FormMode.New

 

OnSelect for the text label:

Set(SelectedItem_Date, DateValue(Selected_Week.Text));
If(IsBlank(Self.Text), NewForm(EditForm));
Set(ShowDetail, true)

 

richw6418_1-1600391755525.png

 

The EditForm is used to view/edit detail, or add a new item to MySPList.

Datasource

MySPList

DefaultMode

FormMode.Edit

 Items

LookUp(MySPList, WeekEndDate = SelectedItem_Date && Categories.Value = Gallery1.Selected.Value)

 Combo box (Categories)' DefaultSelectedItems

Gallery1.Selected

DatePicker's DefaultDate set to the variable when select the text label

SelectedItem_Date

 

With these, I'm able to click on an existing Event to see the details and edit it, or click a blank area to add a new event in. Originally, I was struggling to use Gallery.Selected to identify an item, so could be used by DisplayForm or EditForm, while the Screen wanted multiple items/rows, it turned to be impossible with a single gallery.

Hi @richw6418 :

Thank you for your summary, it will be very useful for users who are stuck in similar problems.

Best Regards,
Bof

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,450)