Skip to content

Commit

Permalink
Update table.js
Browse files Browse the repository at this point in the history
Added title and no data message
  • Loading branch information
scottgruenewald authored Oct 18, 2023
1 parent 471b502 commit 4273c66
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion table.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class GoogleSheetTable {
constructor(url, mainSelector = 'main', title = '') {
constructor(url, mainSelector = 'main', title = '', noDataMessage = '') {
this.url = url;
this.mainElement = document.querySelector(mainSelector);
console.log(this.mainElement)
this.table = null;
this.title = title
this.noDataMessage = noDataMessage
this.uniqueId = Math.random().toString(36).substring(2); // Generate a random unique ID for each table

}
Expand Down Expand Up @@ -75,6 +76,23 @@ class GoogleSheetTable {
return tbody;
}
renderTable(data) {


if (data.length === 0) {
const messageElement = document.createElement('h2');
messageElement.innerText = this.noDataMessage;
this.mainElement.appendChild(messageElement);
return;
}


if (this.title) {
const titleElement = document.createElement('h2');
titleElement.innerText = this.title;
this.mainElement.appendChild(titleElement);
}


this.table = document.createElement('table');
this.table.className = 'table table-striped table-bordered'; // Bootstrap classes for styling

Expand Down

0 comments on commit 4273c66

Please sign in to comment.