CMS Sort by dynamic value

Hi

I’m currently in the progress of developing a page that will allow a user to enter an address and hit a search button.

Once the search button is clicked, I fetch the coordinates of the addess and use Turf.js to calculate the distance between the items in my collection list (lat and lng are stored as custom attributes).

The calculation works fine and I populate a text block with the distance, however I’m struggling to get the collection list to then automatically sort in order from nearest to furthest.

I’m very new to Finsweet so would apprecaite some extra detail in how this should be achieved, I believe I have set it up correctly but for some reason it never sorts.

Just pointing me in the right direction of how it should work would be amazing.

Answered your DM!