Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

GoogleScripts: Sort datarange alone not google spreadsheet [closed]

$
0
0

I got the below code from google for retrieving last 10 records- I am trying to sort the resulting range alone which will be displayed in html form.Problem is the below sorting order sorts on my 4th column, but I also want to sort next by 2nd column. - How to achieve that?

const SPREADSHEETID = "<<sheetid>>";const DATARANGE = "Data!A2:F";const DATASHEET = "Data";function readRecord(range) {  try {    let result = Sheets.Spreadsheets.Values.get(SPREADSHEETID, range);     return result.values;  } catch (err) {    console.log('Failed with error %s', err.message);  }}function getLastTenRecords() {  let lastRow = readRecord(DATARANGE).length + 1;  let startRow = lastRow - 20;  if (startRow < 2) {     startRow = 2;  }  let range = DATASHEET +"!A" + startRow +":" + LASTCOL + lastRow;  let lastTenRecords = readRecord(range);  Logger.log(lastTenRecords);  return lastTenRecords.sort((a, b) => a[4] > b[4] ? 4 : -4);}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>