(oh wow, honoured to start the first custom extension topic)
I am developing an extension to manage orders based on an ‘Orders’ table and a (linked) ‘Order Line Items’ table. My next objective is to allow line items to be re-ordered by the user via drag-and-drop.
I assume I can achieve this by adding a integer field to the table which gets updated by the drag event (?), but since this actually also is a native Airtable UI functionality and you can order records via drag-and-drop when your table/view isn’t sorted – I’m wondering whether someone knows anything of a custom order index being accessible or anything?
I’m guessing not, since I can’t find anything like that in the API docs…
But maybe you have other ideas to achieve this other than the one I mentioned? Or experience with a similar feat and you’ve got a js library you’d like to suggest or something?
Thanks in advance!
(And btw, I’m so glad I found this Discourse forum just now, because the new Airtable community thing truly isn’t it. Thanks guys!)
Welcome to the community, @Tom_Keysers! Glad to have you here!
I actually don’t have personal experience with developing custom extensions, so unfortunately I don’t have an answer to your question — but I just wanted to welcome you here!
We do have several custom extension developers in our forums here — hopefully one of them will be able to chime in to help you out!
I’ve written scripts that sort a linked record field based on how a user drag-and-drops to arrange the child records in the linked table. The main reason why I didn’t turned it into a marketplace extension is because I didn’t have a solution that I liked in case some of the child records were filtered out of the current view. I have a few ideas, such as sorting those last or warning the user and not performing the sort, but it takes time to work out those kinks and time is always in limited supply.
I have also written a script and marketplace extension for sorting linked records based on a field in the child record, such as a date field or a numeric field.
Does that mean there is a way to programmatically get the “custom order” index of records? Because that’s essentially what I’m looking for.
So, just to be extra clear (because maybe I wasn’t): I am talking about letting users sort line items (which are records) via drag-and-drop purely through the custom extension I’m developing. Per this screenshot:
So this is mainly a UI and react related matter, but since there is the “native” functionality of custom sorting records in Airtable, I was hoping to be able to use that data instead of implementing an extra integer field to store and reflect the sequence/index that users made in the custom extension via drag-and-drop. But I’m afraid Airtable has never opened the “custom order” index of records in any API…
The order of the records in the view is inherent in the view. When you select the records in a view without specifying a different sort, you get them in view order.
If you want drag-n-drop in your extension, there are react libraries for drag-and-drop. I don’t recall exact names but I remember that there were several to pick from.
Correct. You cannot edit the sort order of a view directly. You can only edit field values, which in turn can be used by the sort defined for the view. And you cannot programmatically define the sort for a view.
You could store the sort order of a set of records, but I’m not sure what benefit doing so would have. The actual sort order could change at any moment.
Kuovonne is right, all you have to do to reorder the line items is save the linked record id values in the new order created after the drop event, overwriting the old order. Ie the linked record ids are the index. link to page in api reference