orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.26k stars 631 forks source link

Fields\Relation should respect the query's order #2668

Open vilocity-brian opened 11 months ago

vilocity-brian commented 11 months ago

Is your feature request related to a problem? Please describe. The problem is that even if you apply a scope to order the results, the order goes back to ID. This is due to JSON.parse converting the ordered json into an JS object which has no native ordering.

Describe the solution you'd like RelationController::builderItems() should return an array like [{value: 2, label: "First"},{value: 1, label: "Second"}] and relation_controller's search() promise could return response.data directly (skipping the Object.entries)

Describe alternatives you've considered RelationController::builderItems() needs to have the order explicit so that Javascript doesn't lose it. I don't see any other alternative.

tabuna commented 11 months ago

Hi @vilocity-brian. Thanks for bringing this to my attention. Yes, I confirm that there is a problem and no JS object brute force method guarantees order preservation.

There seems to be no other option to fix this than what you suggested.