I’m working on a Vue 2 project that pulls data from Airtable but I’m having trouble with the display order. When I loop through my data using v-for, the items show up in a different order than what I have in my Airtable base.
Template code:
<div class="item-container" v-for="item in items" :key="item.Name">
<h3>{{ item['fields']['Name'] }}</h3>
</div>
In my Airtable I have items arranged as 1, 2, 3, 4 but they render as 2, 4, 1, 3 in the browser. How can I make sure the order matches what I see in Airtable?
you could also sort on the frontend after fetching. just add a computed property or use array.sort() in your component - something like this.items.sort((a, b) => a.fields.Name.localeCompare(b.fields.Name)) after you get the response. not as efficient as server-side sorting, but it works if you don’t want to deal with URL params.
That’s actually normal behavior. Airtable’s API doesn’t keep any specific order unless you tell it to. Your base might look organized, but the API pulls records based on internal IDs, which won’t match what you see visually.
You need to add sorting to your API request. Update your fetchData method with a sort parameter. If you want to sort by “Order” or “Name”, it’d look like this: