function
setup() {
createCanvas(500, 400);
textSize(16);
text(
"Click on the button to display"
+
"all the rows in the table"
, 20, 20);
getColBtn = createButton(
"Show all rows"
);
getColBtn.position(30, 50);
getColBtn.mouseClicked(showAllRows);
table =
new
p5.Table();
table.addColumn(
"movie"
);
table.addColumn(
"rating"
);
table.addColumn(
"price"
);
for
(let i = 0; i < 10; i++) {
let newRow = table.addRow();
newRow.setString(
"movie"
,
"Movie "
+ floor(random(1, 100)));
newRow.setString(
"rating"
,
floor(random(1, 5)));
newRow.setString(
"price"
,
"$"
+ floor(random(10, 100)));
}
}
function
showAllRows() {
clear();
let currentRows = table.getRows();
text(
"There are "
+
currentRows.length +
" rows in the table"
, 20, 100);
for
(let r = 0; r < currentRows.length; r++)
text(currentRows[r].arr.toString(),
20, 140 + r * 20);
text(
"Click on the button to display"
+
"all the rows in the table"
, 20, 20);
}