cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
agneum
Advocate IV
Advocate IV

Keep textboxes persistent on filtered gallery items

I have textboxes next to my items in the gallery where I can enter data. When I make a filter such that the items are updated, the data I wrote in the textboxes disappears.

How can I make the textboxes persistent?

 

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@agneum 

To keep them persistent you would need to update each record in your datasource with the new information typed in.

 

Put this code in the OnChange property of the Text Input.

Patch(
    your_datasource_name,
    ThisItem,
    {ColumnName1: TextInput1.Text}
)

 

Then make sure the Default property of the Text Input is updated to this.

ThisItem.ColumnName1

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

5 REPLIES 5
mdevaney
Super User
Super User

@agneum 

To keep them persistent you would need to update each record in your datasource with the new information typed in.

 

Put this code in the OnChange property of the Text Input.

Patch(
    your_datasource_name,
    ThisItem,
    {ColumnName1: TextInput1.Text}
)

 

Then make sure the Default property of the Text Input is updated to this.

ThisItem.ColumnName1

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

My items are a datasource based off an SQL view. It doesn't have a column for quantity, it just gets the item information.

I use a seperate collection to store items that have non-zero values called SelectedItem. 
Can I patch to the collection?

 

 

@agneum 

How many columns does SelectedItem have?  I assume more than one.  In this code you are only collecting a single column.  You need to define the values for all the columns for collect to work.

 

{Qty: Qty.Text; AnotherField1: "Text", AnotherField2: 1000}

 

Another possibility is Quantity needs to be converted to a number.


{Qty: Value(Qty.Text)}

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

@mdevaney 

I got it to work with the defaultvalue and patch functions. Thanks for your help!


For my Default for the input field I used:

 

LookUp( SelectedItem; ItemId = PRODUCTNUMBER; Qty ) //Identify the row and return its current Qty from the collection

 

 

And for the OnChange for the input field:

 

Patch(SelectedItem;{ItemId: ThisItem.PRODUCTNUMBER}; {ItemId: ThisItem.PRODUCTNUMBER; ItemName: ThisItem.PRODUCTNAME; Qty:Qty.Text})

//Return the record in the collction by ItemId and update it, otherwise it will be created

 



I tried using ThisItem as the second argument as your example suggested, but that gave the error that the function Patch had invalid arguments. I suspect this to be because ThisItem had more columns in it than my collection did. As my datasource wasn't the same as the source I was patching to, I had to specify the record by Id.

 

 

 

Patch(
    SelectedItem,
    ThisItem,
    {ItemId: ThisItem.PRODUCTNUMBER; ItemName: ThisItem.PRODUCTNAME; Qty:Qty.Text}
)

//Did not work for me

 

 


Simliarly setting

 

 

 

ThisItem.Qty

 

 


Didn't work either. I therefore had to find the record with the lookup function. But your post definately got me to the solution, thanks again!



TLDR: Patch function together with ThisItem only works if you are patching to the source the items are read from, or the column definitions match up. If you're patching to another source, specifiy the record by its unique Id (product number in my case).

 

 

@agneum 

I'm glad to hear you got it working.  Thanks for coming back to share your code!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

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