Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

So I've found the following answer in regards to auto-sorting by one column, which works great How can I make some data on a Google Spreadsheet auto-sorting?

However, my use case requires the sorting of two columns. One column is whole numbers, while the second column are dates. I would like to sort the whole numbers column first, then within each number sort the date.

Any suggestions?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Starting with the following line of code:

var range = sheet.getRange("A1:B10");

The sort can be performed in different ways:

  1. range.sort([1,2]);
  2. range.sort([{column: 1, ascending: true}, {column: 2, ascending: true}]);

Both ways are identical as the sort type is by default ascending, but the second option allows for different sort order when TRUE is changed to FALSE.

See reference: range.sort

share|improve this answer
1  
Thanks for the quick response. Your answer makes sense to me. I've implemented the knowledge with success. –  Viet Apr 16 '13 at 18:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.