Create data items
This guide demonstrates how to allow the user to create new data items in a Radzen application.
- Step 1: Create and configure the application
- Step 2: Add the MS SQL Server data source
- Step 3: Create a page and data-bind a grid component
- Step 4: Create the Add Product page
- Step 5: Navigate to the Add Product page
Create a new Radzen application by following the first step from the quickstart guide.
After finishing step 1 you will see again the My Applications screen with your application on it. Click the application to start editing it.
Click the data button in the upper right corner to add the MS SQL Server data source that your application will use.
This will open the My DataSources screen which allows you to add, edit and delete the data sources which your Radzen application uses. Initially this screen is empty because no data sources have been defined. Click the new button to add a new data source.
- Select MS SQL.
- Click use sample MS SQL Server data source. This will populate the configuration options of the sample Radzen service.
- Click the Next button.
Radzen will then infer the schema of the entities exposed by the MS SQL Server data source. Click the Finish button to create the data source.
After finishing step 2 you will see the My DataSources screen. Click the close button at the top right corner.
Click the Create New Page button to add a page. Set the Page Name to Products. Click the Save button.
The page will open in edit mode.
- Drag and drop a DataGrid component from the Components toolbox onto the area that says drop a component. This will add a data grid component to the page.
- Pick the new … option from the Data dropdown.
- Open Operation and set it to getProducts. This will invoke a method of a data source.
- Leave the Response set to value and follow the wizard to the end.
Now that we have the Products page that displays the list of available products let’s make a new page that will create new products!
- Click the Create New Page button to add a page.
- Set the Page Name to Add Product.
- Uncheck Include in navigation. We don’t want this page to appear in the application navigation.
- Click the Save button.
Open the Add Product page for editing by clicking on its label. Now let’s add a form that will capture the new product details.
- Drag and drop a TemplateForm component.
- Open the Schema picker and select Product. This will hint the form designer what properties to enable.
- Click Auto generate. This will add a editor for every property of the selected schema.
- Remove the ID field. We don’t need to specify the ID property of new products because it is generated server-side.
We have created a form that will capture the user input. Now let’s persist the user changes by invoking a data source method that will create a new product.
- Add new Load event handler for the Page and add a new property product equal to
- Add new event handler for the template form Submit event.
- Set Type to Invoke data source method.
- Set Name to createProduct.
- Add a new Parameter.
- Set Name to Product.The createProduct method takes one parameter which represents the product that has to be created.
- Set Value to
- Add a new Then handler. It will execute if createProduct is successful.
- Set Type to Navigate to page.
- Set Path to Products. This will navigate the user to the Products page.
Now let’s navigate to the Add Product page.
- Open the Products page for editing.
- Add new Button component and set Text to
- Go to the Events of the button.
- Add a new handler of the Click event.
- Set Type to Open dialog.
- Set Path to Add Product. This will open the Add Product in a dialog.
You can now run the application to verify that you can add new products.