New table: Reset default sort via script

Hi everyone, I was wondering if its possible to reset to the default sort for a table via scripting, if I have multiple sort conditions?

I initially have a default sort on 3 variables, such that when I load in my table, the sortArray property has 3 objects.

I realized in the script section you can sort using table.setSort({columnId: "a", direction: "asc"}), but when I try to reset all 3 at once, it does not work as intended.

E.g in my script I will write
table.setSort({columnId: "a", direction: "asc"})
table.setSort({columnId: "b", direction: "asc"})
table.setSort({columnId: "c", direction: "asc"})

but after inspecting the state, I see that only table.setSort({columnId: "c", direction: "asc"}) is applied, and the length of sortArray is 1. I have also tried letting setSort take in an array but from the API that doesn't seem to work. I also have not seen any methods that may help me achieve this. Any help would be greatly appreciated!

Instead of

Have you tried

table.setSort({columnId: "a", direction: "asc"},{columnId: "b", direction: "asc"},{columnId: "c", direction: "asc"})

Hi there, thank you for the reply.

Yes, I have tried this as well. Unfortunately it seems to only register {columnId: "a", direction: "asc"} on the sortArray, and the rest of the objects are ignored, so sortArray is only of length 1 and sorted on a, not the others.

If sorting by multiple columns, you need to use an array:

table1.setSort([{columnId: 'role',direction:'asc'},{columnId:'createdAt', direction:'asc'}])

Of course. Pass an array to the sortArray :man_facepalming:. Thanks @Tess