Dynamic Tables in App Inventor using WebViewer and HTML

This week I had a long and interesting discussion with ChatGPT. For personal use I had created an app to record blood pressure measurements, but I became frustrated with the ListView I was using, so I wanted to switch to using an HTML table. I did some research and found some examples which were either too simple, or in Spanish or too difficult. The result of the discussion was a rather generic way of using a WebViewer and Javascript. I made a simplified app, about keeping a list of weight measurements, with a date.


The blocks code is pretty simple, by making a list of column names you determine the shape of the table, like this:

Here is the .aia, that also contains the html needed, but you will see it again in the story by ChatGPT itself:
DynTable_20250410.aia (7.9 KB)
This is the html (change txt to html):
dyntable_flexidates.txt (5.7 KB)
This is the ChatGpt story:
:bar_chart: Dynamic Tables in App Inventor using WebViewer and HTML
With sorting, editing, and CSV export

:white_check_mark: What This Project Does

This App Inventor project uses the WebViewer component to show and manage a dynamic HTML table. It uses JavaScript and JSON to interact with the table from App Inventor blocks.

You can:

  • Add and remove rows
  • Sort by any column (including ISO-formatted dates)
  • Edit specific rows
  • Export the table as a CSV file
  • Save and restore table data using files
  • Show user-friendly date formatting (e.g., 18-04-2025)

:brick: How It Works

The App Inventor side sends commands to the WebViewer using:

WebViewer.WebViewString = JSON-formatted text

:white_check_mark: Basic Commands:

JSON Command Effect
{ "title": "My Log" } Sets the table title
{ "add": { ... } } Adds a row
{ "addTop": { ... } } Adds a row to the top
{ "edit": { match, update }} Edits the first matching row
{ "delete": { field: value }} Deletes a row by field match
{ "clear": true } Removes all rows
{ "sortBy": "Date" } Sorts the table by column (ascending)
{ "save": true } Sends table data back to App Inventor
{ "exportCSV": true } Sends CSV-formatted string to App Inventor

You can combine commands in one JSON:

{
  "title": "Weight Log",
  "load": [
    { "Date": "18-04-2025", "Weight": "72" },
    { "Date": "05-04-2025", "Weight": "68" }
  ],
  "sortBy": "Date"
}

:repeat: Date Handling

  • Users can enter or pick dates as "dd-MM-yyyy" (e.g., 05-04-2025)
  • The HTML converts these to "yyyy-MM-dd" internally so sorting works
  • The table still displays dates in the local-friendly format: dd-MM-yyyy

:package: Included Files

  • dyntable_flexidates.html: the HTML file used in the WebViewer

You can include this file in your assets and load it like this:

WebViewer.HomeUrl = "file:///android_asset/dyntable_flexidates.html"

Note Ghica: use "localhost/dyntable_flexidates.html"instead of the line above. 

:art: Example Block Logic

Here’s how simple the App Inventor blocks can be:

  • On screen initialize:
    Set WebViewer.WebViewString to JSON that includes title, load, and sortBy.

  • To add a row:
    Format a JSON string like:

    { "add": { "Date": "2025-04-10", "Weight": "70.5" } }
    
  • To save the table:
    Send { "save": true } → then capture WebViewer.WebViewString and write it to a file.

  • To restore:
    Read file content → set WebViewer.WebViewString with that JSON.

  • To export CSV:
    Send { "exportCSV": true } → then save the result.

:speech_balloon: Feedback & Credit

If this helps you, feel free to build on it and share your own versions!
Big thanks to ChatGPT for help building the HTML side of the system.
=============== so far for ChatGPT

As you can see ChatGPT is very pleased with itself, but actually there were quite a few hard to find bugs, but finally it came out well I think. I can now start the real app I wanted to make. Have fun with it!

3 Likes

Was it "eat at least 5 Danish pastries a day" week ? :cake: :wink:

Care to share the html/css/javascript used ?

Yes, something like that. You are too quick. See the complete story now.

1 Like

You could have done this with Tableviewer (extension) and a few blocks, bit of javascript...

Yes, maybe, but I did not want to use an extension, in the hope I could someday use it on iOS. And, my Javascript is a bit rusty.
And I shared the HTML, which contains the Javascript, as .txt, because apparently you cannot upload .html directly.

1 Like

(added to FAQ)

Here is a picture of all the blocks needed to build an app. You should make a data entry form using a DatePicker and other text fields. There are a few buttons, to add a row to the table, to store the table (as JSON) in a file on your phone, so that you can find your table in your app the next day, or as CSV, where the CSV file can be uploaded to Dropbox, for example, by using the "Share" button.
I did not implement all functionality that ChatGpt provided, just only what I needed.

My main reason for showing this is that ChatGPT can help you to make useful apps, but there is also a warning that you should check very well whether it really works as intended.

And, so far, ChatGPT could not produce a working .aia although it offered to do that several times. Maybe in some future you give it a description, and out comes the .aia!

I knew I had already been down this road :wink:

Perhaps ChatGPT stole it from you!