List a single customer (SELECT)
Best practice for production apps is to use REST as the data layer to access data and not directly integrate to SQL using the SQL data provider. The SQL data provider will be squiggled in blue to indicate it is not recommended, together with a message to use REST instead. See REST endpoints from Azure SQL for more information.
Scenario
View the customer's details by pressing on the customer in the list, which opens the customer's details in a default .
Resources
Jigx Code
The Azure SQL Docs solution is on GitHub.
This example selects a customer from the list and uses the CustomerId to return the customer's details to the default on the device, using the SQL data provider's function, where it is stored in the SQLite database. In the default the data is selected from the SQLite database using a SQL query in a data source which in turn is used by the to render the details in entity fields. The functions used to return a single record use forRowsWithMatchingIds: true. Only records in the SQLite table with a matching id will be updated. When forRowsWithMatchingIds is false or omitted, all records in the SQLite table will be deleted, and only the records returned by the stored procedure, or query statement will be inserted.
The function is listed twice, once for executing a stored procedure and once for executing a query.
The listCustomers.jigx file must be modified to include an onPress action. When pressing on a list item in the customer list, will navigate to the viewCustomer.jigx. customerId is specified as a parameter that should be passed to the viewCustomer.jigx, where it is used in the WHERE clause of the SQLite query to load the selected customer.
Add the onPress code to the bottom of the listCustomers.jigx file:
The WHERE clause in the query contains a token for a parameter called customerId that is defined in queryParameters and is passed to the viewCustomer jig as an input from the listCustomer jig.
The isDocument property for the mydata datasource is set to true. As a result, the data source will return as a single record to be displayed on a form instead of an array of records.
The data on the displays using an entity and entity- fields component. If the data source returns an array, an entity component will automatically show the first record.
The YAML for viewing the selected customer is:
Add the list of customers to the home screen with a widget size of 4x4 which automatically shows the list in the widget.