Edit data items (Angular)
This guide demonstrates how to allow the user to edit data items in a Radzen application.
Quick video - CRUD pages from data source
Step-by-step
- Step 1: Create and configure the application
- Step 2: Add the OData service
- Step 3: Create a page and data-bind a grid component
- Step 4: Create the Edit Product page
- Step 5: Navigate to the Edit Product page
Step 1: Create and configure the application
Create a new Radzen application by following the first step from the quickstart guide.
Step 2: Add the OData service
Add a data source by following step 2 from the create data items guide.
Step 3: Create a page and data-bind a grid component
Add a data grid component and data-bind it by following step 3 from the create data items guide.
Step 4: Create the Edit Product page
- Click the Create New Page button to add a page.
- Set the Page Name to Edit Product.
- Uncheck Include in navigation. We don’t want this page to appear in the application navigation.
- Click the Save button.
Now it is time to load the product that the user will edit. We will use a route parameter called Id to get the current product.
- Open the Edit Product page for editing.
- Click on an empty space in the design canvas to show the Page Events.
- Add a new handler of the Load event.
- Set Type to Invoke data source method.
- Set Name to getProductById.
- Add a new Parameter.
- Set Name to ID.
- Set Value to
${parameters.Id}
. - Add a new Then handler.
- Set Type to Set property.
- Set Name to product.
- Set Value to
${result}
.
This sequence will load the product by invoking the getProductById
method and store the result in the product
page property.
We will use that property to data-bind the edit form.
We are ready to add the edit form.
- Drag and drop a Form component.
- Set Data to product. This will data-bind the form to the product page property.
- Click Auto generate. This will add a form field for every property of product property.
- Scroll to the ID field and remove it. We don’t want our users to update the ID property.
We have to handle the Submit event of the form in order to persist the changes.
- Click Events in the property grid.
- Add a new event handler of the Submit event.
- Set Type to Invoke data source method.
- Set Name to updateProduct.
- Add a new Parameter.
- Set Name to ID.
- Set Value to
${parameters.Id}
. - Add a second Parameter.
- Set Name to Product.
- Set Value to
${event}
. The form component provides the user input as an event argument of the Submit event. - Add a new Then handler. It will execute if updateProduct is successful.
- Set Type to Close dialog.
Step 5: Navigate to the Edit Product page
Now let’s navigate to the Edit Product page (we will create it in the next step).
- Open the Products page for editing.
- Select the DataGrid component.
- Go to the Events of the DataGrid.
- Add a new handler of the Select event.
- Set Type to Open dialog.
- Set Path to Edit Product. This will navigate the user to the Edit Product page.
- Add a new Parameter. The Edit Product page will use that parameter to load the specified product.
- Set Name to Id.
- Set Value to
${event.Id}
.
You can now run the application to verify that you can edit products.