Код:
async function sortSchedule(): Promise {
const table = Context.data.paymentSchedule;
if (paymentSchedule && paymentSchedule.length > 0) {
let sortTable = table.map(f => f);
sortTable.sort((a, b) => {
return a.paymentDate.before(b.paymentDate) ? -1 : a.paymentDate.after(b.paymentDate) ? 1 : 0;
}
);
for (let i = table.length - 1; i >= 0; i--) {
table.delete(i);
}
for (let i = 0; i < sortTable.length; i++) {
let row = table.insert();
row.paymentDate = sortTable[i].paymentDate;
row.amount = +(sortTable[i].amount ?? 0).toFixed(6);
}
}
Context.data.paymentSchedule = Context.data.paymentSchedule;
}
}
Ссылки: https://tssdk.elma365.com/ru/pages/quick-start/intro_tables.html#сортировка-данных-в-таблице-метод-sort