How do you create a table (grid) to edit or delete items

My goal is to enter some data in fields and insert them into a table data, like this:

So you can see in the table there are 2 buttons: one for edit data and another one for delete data.

None of them. The line must be delete from the table, so the row must contains '1,3' only.

Remember that all data is from an SQLite table.

Which items in the row will be editable ? All three ? e.g. Tinta Amarela, Baldes and 20

Yes!!

You will need to "maintain" the record ID if you want to write back any changes to your sqlite DB.

Does your table have to fit the screen, or can it scroll horizontally to view more columns? I assume it will also be OK for your table to scroll vertically....

Yes, it can scroll horizontally without problem. And yes, it must scroll vertically.

It is taking me a bit longer than planned, mostly due to the formatting required....and real world events getting the way of play time :wink:

1 Like

Don't worry... take your time. I understand and appreciate all your efforts in helping me.

Herewith an aia project example using the Tableviewer extension (credits @Kevinkun !!)

tvEditable.aia (31.1 KB)

Notes:

  • I set some source data which should represent the query output from sqlite, including the record id. This is needed for writing back an updated record, or deleting a record from the sqlite table. I have not handled this part, but include procedures where additional sqlite blocks can be used.
  • the source data is tidied up for the table data, removing the id and adding the two icons for each row
  • I used emojis for the edit and delete icons. It is possible to also use images from local or url sources
  • You can do more editing to the table format to remove borders as required
  • I have written code for the Tableviewer click event, so that only the icons generate a response
  • You can improve the formatting for the edit/update dialog if you wish
  • This table fits the screen on my phone horizontally, and it will scroll vertically if many more records are added, beyond the height of the screen. You can add further formatting to the table to get a sticky header row.

ref Tableviewer

BLOCKS

SCREEN

image

ref nth-child recipes

3 Likes

Wow, fantastic!! Thanks so much for your help. This fits exactly what I need. I don’t have words to thank you!!!

I am working on a CompCreator version as well....

You can have a choice with this one. Would you prefer to edit a record in place in the displayed list, or do as I have done for Tableviewer and open a dialog?

1 Like

I prefer to open a dialog.

1 Like

Here you are with an aia project example of using CompCreator (credits @Kevinkun !) to generate a displayed table that allows editing of a record or the deletion of a record

ccEditable.aia (40.5 KB)

NOTES:

  • The table is set in a vertical scrolling arrangement, so should scroll when more records than the height of the screen are added. On my phone the table fits well horizontally.
  • The blocks look complicated at first, but once you get the hang of how to create components, and then more components inside components, and then format components either individually or collectively, then it starts to make sense
  • I create the vertical scrolling arrangement "outer", then add a horizontal arrangement, for the header, then for each record. Inside these I set three textboxes (only four labels for the header) and two buttons. For the buttons I also generate a list of the edit buttons and the delete buttons. The indexes of these two lists are used to run actions (edit/update or delete) on the tableData list, after which the table is redrawn with the new data. The record ID from the sourceData table is also captured.
BLOCKS

SCREENS

image

CompCreator

1 Like

Perfect @TIMAI2 !!! Thank you very much!! Now I have too much material to study and apply in my App.

Just to round things off, a third example that provides for "in place" editing of a Tableviewer!

tvEditableContent.aia (33.3 KB)

NOTES

  • With this example, when you press on an Edit icon (pencil), it makes the three items in that row editable, just like you see with AI2 textboxes. The pencil icon is changed to an "OK" symbol. To make changes, or cancel out, the "OK" symbol must be pressed, to offer the user options of either updating or canceling.
  • This example uses javascript to make the table cells editable (or not), and to return the edited values.
  • The record ID (rowID) is returned in a variable, as in the other examples.
  • More work can be done to rationalise the blocks, I did much of it "longhand" which may make it easier to see what is going on.
  • You can only edit one row at a time, the blocks programming prevents editing multiple rows at once (by accident, not by design !).
BLOCKS

SCREENS

Fantastic. Just a question: how to proceed to insert a new line?

OK , if you want full CRUD on an sqlite table using Tableviewer, then a different/better approach required. Watch this space

1 Like

See now an aia project example of SQLite with Tableviewer full CRUD (Create,Read,Update,Delete)

sqliteCRUDwithTableviewer.aia (57.0 KB)

Notes

  • This comes with a sample db in the assets, which is copied to the ASD on first run, and set as the default database. (Backup up your database if you already have one in companion app, as this will be overwritten)
BLOCKS

SCREENS

Create

Read

Select option

Update

Delete

Before you ask for filtering of list, or other features, most of these can be done with sqlite queries on the underlying data.

2 Likes

Hi @TIMAI2

Thank you very much for your help and time to create a solution. In fact I was trying to do myself a way to insert a record on the table, based on your previous posts about TableViewer. But now I'm going to apply those ideas to my app. It's not necessary filter or other things like this.

Once again, thank you!!!

A post was merged into an existing topic: [Free] CompCreator - create component dynamically

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.