Lesson 2 - Work with Data in UI
This tutorial takes you through the process of viewing and editing individual records via forms.
View details for each record
From the Widgets tab, drag and drop a Form widget on the canvas to the right of the Table widget.
Click the title Form. On the property pane to the right of the screen, in the Text property box, change the title from Form to
User Details
.Now add widgets on the Form to view user details. For the user's name, drop an Input widget inside the Form.
- On the property pane to the right, click on the default name Input1 and rename it to
nameInput
. - In the Text property box, enter
Name
. - In the Default Value property box, type
{{usersTable.selectedRow.name}}
. This displays the user's name of the selected row on the usersTable Table widget.
- On the property pane to the right, click on the default name Input1 and rename it to
You also need to view the user's date of birth. Drop a Datepicker widget inside the Form.
- Rename the widget to
dobInput
. - In the Text property box, enter
DOB
. - Click the JS button next to the Default Date property to connect the Datepicker widget to the user's date of birth on the Table.
- Type
{{usersTable.selectedRow.dob}}
in the Default Date property box. - In the Date format property, select the LL date format.
- Rename the widget to
And finally to view the user's photo, drop an Image widget inside the Form.
- In the Image property box, type
{{usersTable.selectedRow.image}}
.
- In the Image property box, type
🚩 You've completed binding the data to the widgets on the Form. Select the rows on the Table to view the corresponding user details on the Form.
Update records
Select the Explorer tab on the Entity Explorer to the screen's left.
Click the + icon next to Queries/JS.
Select usersTutorialDB query from the list of options.
Rename the query to
updateUsers
. Delete the default fetch query template.Paste the below SQL update command in the query editor to update the
users
table in the database with the details modified in the Form.UPDATE users
SET name = {{nameInput.text}},
dob = {{dobInput.selectedDate}}
WHERE id = {{usersTable.selectedRow.id}}
Trigger update on button click
Go back to the canvas by clicking on the User Information page on the Entity Explorer.
To connect the updateUsers query to a button, select the default Submit button on the Form.
- On the property pane to the right of the screen, in the Label property box, change the label to
Update
. - Click the + icon next to the onClick event.
- In the Action list, select Execute a query > updateUsers to run the query on button click.
- Click the + icon next to the onSuccess callback.
- Select Execute a query > getUsers.
The button is now configured to execute the updateUsers query to save any modified user details on the Form and to refresh the Table widget with the updated information.
- On the property pane to the right of the screen, in the Label property box, change the label to
Select the first row on the Table. Go ahead and modify the user's name on the Form and test the Update button to see if the update worked.
cautionThe databases used in tutorials are public and shared by all Appsmith users, so ensure that you don't input confidential information during testing. The databases are automatically reset every day, so any updates made to these databases are temporary.