How to edit and save rows from table

Hi, It is my first app and i'm learning programming so I may need extra help on the resolution !

I want to be able to edit one or more rows in my table then apply the changes using the save button.

The query i'm using to populate the table is the following:

SELECT
  "Inventory"."ID",
  "Inventory"."BarCode",
  "Customers"."Name",
  "Volumes"."Description" AS "VolumeDescription",
  "Inventory"."ReceivingDate",
  "Locations"."Description" AS "LocationDescription",
  "Inventory"."DeliveryDate"
FROM
  "Inventory" AS "Inventory"
  LEFT JOIN "Customers" AS "Customers" ON "Inventory"."CustomerID" = "Customers"."ID"
  LEFT JOIN "Volumes" AS "Volumes" ON "Inventory"."VolumeID" = "Volumes"."ID"
  LEFT JOIN "Locations" AS "Locations" ON "Inventory"."LocationID" = "Locations"."ID" 
ORDER BY "ID" DESC

I don't have a clue on what to write in my query to save the changes made to any of the columns
Ex : If I change the Customer (Client) and the Volume for multiple rows and click save. I want the rows to be updated in the DB (retooldb)

Welcome to Retool (and programming in general)!

Your case is a pretty straightforward one for many use cases in our apps. If you intend to allow for multiple rows to be updated the GUI action you want to use is Bulk Update via Primary key (but this also works for a single row):

image

This lets you choose your table's PK directly (which I believe you currently have hidden from your table display). The Array of records to update will be your table's changesetArray, which can be accessed using {{yourTableName.changesetArray}}

Lastly, sometimes you may need to send all of the row data to the query to be able to access unique values/columns, in which case you can toggle that option on in the table's Interaction setup:

image

2 Likes

Hi,

It does work for all fields except the those using foreign keys.
Here's some row of my database


When I try to save it is returning the customer name and not the ID !
image

What should I do ?