Answer the question
In order to leave comments, you need to log in
Can anyone help with onEdit()?
There is a table with time lines
10:00
11:30
12:00
and so on.
How can I make it so that when editing the time, my time is sorted? I know how to sort it by the button, but I’m not familiar with onEdit ()
Thanks in advance for the answers
Answer the question
In order to leave comments, you need to log in
1) Get the values
2) Filter, keep only the dates
3) Sort
4) Paste the result back
function onEdit(event) {
//* Боев Григорий (с) 2020 (telegram @ProgrammerForever)
const ss = event.source.getActiveSheet(); // Текущий лист
const row = event.range.getRow(); // Номер строки
const col = event.range.getColumn(); // Номер столбца
const rowsCount = ss.getMaxRows(); // Кол-во строк
const inRange = ss.getRange(1,col,rowsCount,1);
var inData = inRange.getValues(); // Получение значений
inRange.clearContent(); // Удаление старых
inData = inData.filter(row=>row[0].getTime); // Оставить только даты
inData.sort((a,b)=>a[0].getTime()-b[0].getTime()); // Сортировка
ss.getRange(1,col,inData.length,1).setValues(inData); //Вывод
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question