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 III
Super User III

@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 III
Super User III

@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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (44,723)