I changed data in text and dropdown values which is there in gallery and when i click on back button it should popup there is unsaved values else it should be back page.
Solved! Go to Solution.
is there is any way to check collection as changed?
There is no way to easily compare one collection to another (i.e. your Gallery).
Simply setting a variable as was mentioned by @jatcube is an option, but it will not give you the row level ability to determine what is changed. And, more importantly, when you go to write changes, would cause you to write all of your data - changed or not.
There are two other options that are more efficient:
1) Utilize an in-memory database (collection) of changed rows. Instead of a flat out - set a variable to true or false, instead, collect the ID (primary key) of your row in a collection. This would utilize all of the OnChange actions of your controls in the gallery. Each would simply have the following: Collect(colChangeList, ThisItem.ID)
This list can be checked when the user attempts to go back (i.e. CountRows(colChangeList)>0 ) to determine if there are changes. This collection should be cleared when the screen is first shown (OnVisible).
Writing your data would be based on the colChangeList.
Ex.
Patch(yourDataSource,
ForAll(Distinct(colChanges, Value),
With(LookUp(yourGallery.AllItems, ID=Result),
{ID: ID,
ColX: controlForColX.Text,
...etc...
}
)
)
)
While this will work, it will record any change and not reflect if a user "unchanges" data. In other words, they change something and then change it back. In this scenario, the record would still be written.
2) Employ a checkbox or toggle control in your gallery row.
In this scenario, you would set the Default property to do comparison from your underlying data to the values entered in the controls. If there are any differences, the control will be "true". That can be used later to write the data and also determine if there are changes prior to going "back".
For example on the Default property, the formula would be like:
!(ThisItem.ColX = controlForColX.Text) ||
!(ThisItem.ColY = controlForColY.Value) ||
...etc..
To then determine if there are changes, you would simply look to see if there are any checkboxes/Toggles that are true.
ex.
CountRows(Filter(yourGallery.AllItems, yourCheckBox.Value))>0
And then your write-back formula would be more like this:
Patch(yourDataSource,
ForAll(Filter(yourGallery.AllItems, Checkbox.Value),
{ID: ID,
ColX: controlForColX.Text,
...etc...
}
)
)
With the scenario, if a user changes a record and then sets it back, your app will not waste time in updating the record.
Hopefully this is all clear and helpful.
That's simple, please apply the following steps :
This should work for you.