function setup() {
createCanvas(500, 300);
textSize(16);
getColBtn = createButton("Get Table Row Details");
getColBtn.position(30, 50);
getColBtn.mouseClicked(getTableRows);
getColBtn = createButton("Clear Rows");
getColBtn.position(30, 80);
getColBtn.mouseClicked(clearAllRows);
text("Click on the button to clear the"+
" rows in the table", 20, 20);
table = new p5.Table();
table.addColumn("author");
table.addColumn("book");
let newRow = table.addRow();
newRow.setString("author", "Marcel Proust");
newRow.setString("book", "In Search of Lost Time");
newRow = table.addRow();
newRow.setString("author", "James Joyce");
newRow.setString("book", "Ulysses");
}
function clearAllRows() {
clear();
text("Click on the button to clear"+
" the rows in the table", 20, 20);
table.clearRows();
text("All rows cleared!", 20, 140);
}
function getTableRows() {
clear();
text("Click on the button to clear the rows "+
"in the table", 20, 20);
text("There are " + table.getRowCount() +
" rows in the table", 20, 140);
for (let i = 0; i < table.getRowCount(); i++) {
let rowContents = table.rows[i].arr.toString();
text("Row " + i + ": " + rowContents, 20, 160 + i * 20);
}
}