-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort by Multiple Columns #7
Comments
I haven't looked in the ruby code, but it seems that sort was an array with field and direction. The sort should be json object like this:
|
Thanks, yes that appears to be the format for sorting by a single field. What I'm trying to figure out is how to sort by multiple fields. For example, I want to sort a list of students by dormitory, then name, via the API. The best I've been able to come up with is to use a |
@dmerand can you try sortBy branch to see if that works for you? |
I tried the sortBy branch in my code, and it's working great! Thanks for taking the effort to make this update. It's very cool to be able to work directly on the returned object, rather than convert it to an array + sort it, which was my previous approach. |
...I think I was able to install the gem from GitHub from sortBy branch, but I cannot figure out how to use multiple keys. Have tried so far: @rec = @tbl.records(:sort => [["key1", :asc], ["key2", :asc]]) @rec = @tbl.records(:sort => ["key1", :asc]) Could you give an example on how to use the multiple key sorting properly? |
@Etsija try sortByTake2 branch - it now handles :asc being a symbol. |
Hi,
Looking at the API docs, it seems that Airtable should be able to support sorting via multiple columns via the API:
But I'm noticing that the
records
method (among others) inlib/airtable/table.rb
seems to hard-code sort at one parameter:I've tried simply commenting out the first line of that method and passing my own sort object (ie
sort: [{field: 'fieldName', direction: :asc}]
, but likely due to my unfamiliarity with HTTParty or the Airtable API, I can't figure out how to pass multiple sort objects through therecords
method.Basically: I would have submitted a pull request to adjust this method to allow multiple sort, but I can't figure it out :/ Hopefully you know more than me on the topic.
Thanks!
The text was updated successfully, but these errors were encountered: