Reputation:
I am a beginner to appscript. I am doing a resident payment system where the user will enter username and password first and after logging in they can view the payment history. For now it is showing the all the payment data in the database but I want to only show the last 12 rows. Can anyone help me on this me? I have attached some images and link to my appscript to explain myself better. Thanks in advance.
https://script.google.com/d/1xV7FDVgp10XbGFtPJDUnhqm1GYybKZeKEI2L84Slp34rndOWgVJ1iScm/edit?usp=sharing - Link to my appscript coding
https://script.google.com/macros/s/AKfycbxFJTD9f6cMMDYDHw5sY6bENOmC52Z_7-mkGmnNGkQ-B5-j-63Q4aOcgetX4MWYIfW6/exec - Link to my executed version (Web App)
USERNAME : JJACKSON
PASSWORD : PASSWORD1
Upvotes: 3
Views: 76
Reputation: 201378
When I saw your script of your shared Google Apps Script project, in that case, how about the following modification? In this case, please modify the function of displayTable()
at the HTML & Javascript side as follows.
function displayTable(ar) {
function displayTable(ar) {
ar = ar.splice(-12); // <--- Added
displayTable
is called after GetRecords
at Google Apps Script side was called, when "Login" button is clicked. In this case, the values from GetRecords
is the 2 dimensional array. In this answer, the value you expect is retrieved from this array by ar = ar.splice(-12)
.From your following replying,
Bro if I am not mistaken, it will only minus 12 rows right. In the AppScript right every year new 12 rows ( which means in 2022 new rows will be added from January 2022 until December 2022). So this logic will be a problem later bro. Hope you will me in this bro. Thank you bro.
In this case, how about the following modification?
function displayTable(ar) {
function displayTable(ar) {
ar = ar.sort((a, b) => new Date(a).getTime() > new Date(b).getTime() ? -1 : 1).splice(-12); // <--- Added
In this case, the last 12 months are retrieved from ar
.
If you want to retrieve the 12 months as the descending order, how about the following script?
ar = ar.sort((a, b) => new Date(a).getTime() > new Date(b).getTime() ? 1 : -1).splice(0, 12);
Upvotes: 2