Skip to main content

Query a grouped view via JavaScript API?

  • December 3, 2021
  • 4 replies
  • 56 views

I have a view that is being grouped by two fields. When I do myView.selectRecordsAsync(); I get a flat list of records, though. Do I have to redo the grouping in JavaScript or is there a way for this to return a nested list that’s the same structure as my grouped view?

4 replies

JonathanBowen
Forum|alt.badge.img+18
  • Inspiring
  • 1110 replies
  • December 3, 2021

Hi @Michael_Henry1 - yes, the records returned from a script query are “flat” and don’t take account of any groups you’ve made in the UI. But the results will take acount of the filters you have applied (if any).


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • December 3, 2021

In my experience, not only is the query result “flat”, it is not in the order displayed in the user interface. The results are sorted according to any specified sort, but not sorted according to grouping. Records from different groups may be interleaved with each other.


Justin_Barrett
Forum|alt.badge.img+21
  • Inspiring
  • 4647 replies
  • December 5, 2021

In my experience, not only is the query result “flat”, it is not in the order displayed in the user interface. The results are sorted according to any specified sort, but not sorted according to grouping. Records from different groups may be interleaved with each other.


I just ran a test, and the returned records from querying a specific view with grouped records did maintain the group order, including the record order inside each group. Granted it was a small sampling, but I’d like to think that this behavior would extend to larger datasets as well.


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • December 5, 2021

I just ran a test, and the returned records from querying a specific view with grouped records did maintain the group order, including the record order inside each group. Granted it was a small sampling, but I’d like to think that this behavior would extend to larger datasets as well.


Awesome. Airtable must have quietly fixed.