简体   繁体   中英

Google Sheets how to sort two columns in ascending order

I have a google sheet table and need to select a data range and sort data using two columns in ascending order.

I have tried the following and it does not work:

var range = sheet.getRange( vRowStartFan, 1, (sheet.getLastRow() - vRowStartFan), sheet.getLastColumn() );
range.activate();
sheet.sort(col, true).sort(1, true);

What should I do? thanks in advance for any help

function sortTipsByCurrentColumn( sheet, col ) {
var range = sheet.getRange( vRowStartFan, 1, (sheet.getLastRow() - vRowStartFan), sheet.getLastColumn() );      
range.activate();
range.sort( [{column: col, ascending: true}, {column: range.getColumn(), ascending: true}]);

}

using range.sort allows the usage of more than 1 column for sorting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM