Data Providers
Microsoft Azure SQL

List a single customer (SELECT)

8min


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.

List & view customer detail
List & view customer detail


How it works

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.

Functions

The

 function is listed twice, once for executing a stored procedure and once for executing a query.

A store procedure-based version of get-customer.jigx

get-customer.jigx


A query-based version of get-customer.jigx

get-customers.jigx


Jigs

Modifying the list customers jig

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:

listCustomers.jigx


View customer jig

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:

viewCustomer.jigx


index

Add the list of customers

 to the home screen with a widget size of 4x4 which automatically shows the list in the widget.

index.jigx