Datasources
Datasources are sets of data used in Jigx solutions and are used to reference data from the various Data Providers.
Types
There are three types of datasources available in Jigx Builder.
Static - Static lists are typically used when data needs to be accessed but hardly ever changed. Static Data is helpful because it can be created quickly inside the jig, and there is no need to specify any database connections or set up tables. The amount of records that can be created in Static data is unlimited. Static data is commonly used to bind data to the UI components. For code examples and snippets, see Static.
System - The system datasource is used to get a list of icons for jig components. For code examples and snippets, see system.
Configuration options
isDocument
When the isDocument property is set to true on a datasource, the datasource will return as a single record (object) to be displayed on a component instead of an array. The first matching row becomes the datasource without wrapping the array. If there is no match it is NULL. If you want to set the initialValues for a form, set it on the form level and in the datasource isDocument: true, this way you don't have to set it up in the individual components. It is set up in one place and form will match the components to the column names of the datasource.
jsonProperties
Working with complex objects can be tricky, as they include arrays, nested objects, and other complex data structures. When integrating and manipulating these JSON structures you can use jsonProperties to specify the exact property in the array or nested object that you require. See Working with complex REST structures.
isDocument example
datasources:
contactData:
type: datasource.sqlite
options:
# The isDocument property for the datasource is set to true.
# As a result, the datasource will return as a single record to be displayed,
# instead of an array of records.
isDocument: true
provider: DATA_PROVIDER_DYNAMIC
entities:
- default/contacts
query: |
SELECT
id,
'$.firstName',
'$.lastName',
'$.jobTitle',
'$.companyName',
'$.phone',
'$.email'
FROM
[default/contacts]
WHERE
id = @contactId
queryParameters:
contactId: [email protected]{
"contacts": [
{
"id": 1,
"firstName": "Merilyn",
"lastName": "Bayless",
"companyName": "20 20 Printing Inc",
"phone": "408-758-5015",
"email": "[email protected]",
"web": "http://www.printinginc.com",
"jobTitle": "Project Manager"
}
]
}title: Add new contact A
type: jig.default
icon: book-address
inputs:
id:
type: string
required: true
header:
type: component.jig-header
options:
height: medium
children:
type: component.image
options:
source:
uri: https://images.unsplash.com/photo-1517245386807-bb43f82c33c4?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1740&q=80
datasources:
contactData:
type: datasource.sqlite
options:
# The isDocument property for the datasource is set to true.
# As a result, the datasource will return as a single record to be displayed,
# instead of an array of records.
isDocument: true
provider: DATA_PROVIDER_DYNAMIC
entities:
- default/contacts
query: |
SELECT
id,
'$.firstName',
'$.lastName',
'$.jobTitle',
'$.companyName',
'$.phone',
'$.email'
FROM
[default/contacts]
WHERE
id = @contactId
queryParameters:
contactId: [email protected]
children:
- type: component.form
instanceId: new-contact
options:
initialValues: [email protected]
isDiscardChangesAlertEnabled: false
children:
- type: component.avatar-field
instanceId: employee-photo
options:
label: Photo
- type: component.section
options:
title: Personal information
children:
- type: component.text-field
instanceId: firstName
options:
label: First name
- type: component.text-field
instanceId: lastName
options:
label: Last name
- type: component.email-field
instanceId: email
options:
label: Email
icon: email
- type: component.number-field
instanceId: phone
options:
label: Phone number
icon: phone
- type: component.section
options:
title: Business information
children:
- type: component.text-field
instanceId: jobTitle
options:
label: Position
- type: component.text-field
instanceId: companyName
options:
label: Company Name
actions:
- children:
- type: action.execute-entity
options:
title: Create Record
provider: DATA_PROVIDER_DYNAMIC
entity: default/contacts
method: create
data:
firstName: [email protected]
lastName: [email protected]
email: [email protected]
phone: [email protected]
jobTitle: [email protected]
companyName: [email protected]jsonProperties example
datasources:
customers:
type: datasource.sqlite
options:
provider: DATA_PROVIDER_LOCAL
entities:
- entity: customers
query: |
SELECT
cus.id AS id,
json_extract(cus.data, '$.firstName') AS firstName,
json_extract(cus.data, '$.lastName') AS lastName,
json_extract(cus.data, '$.companyName') AS companyName,
json_extract(cus.data, '$.addresses') AS addresses,
json_extract(cus.data, '$.phones') AS phones,
json_extract(cus.data, '$.email') AS email,
json_extract(cus.data, '$.web') AS web,
json_extract(cus.data, '$.customerType') AS customerType,
json_extract(cus.data, '$.jobTitle') AS jobTitle
FROM
[customers] AS cus
ORDER BY
json_extract(cus.data, '$.companyName')
# Specify the exact property in the array or nested object that you require.
jsonProperties:
- addresses
- phones
data: [email protected]
item:
type: component.list-item
options:
title: [email protected]
subtitle: [email protected] & ' ' & @ctx.current.item.lastName
description: [email protected][0].city
leftElement:
element: avatar
text: [email protected][0].state
label:
title: =$uppercase((@ctx.current.item.customerType = 'Silver' ? @ctx.current.item.customerType:@ctx.current.item.customerType = 'Gold' ? @ctx.current.item.customerType:''))
color:
- when: [email protected] = 'Gold'
color: color3
- when: [email protected] = 'Silver'
color: color14
onPress:
type: action.go-to
options:
linkTo: view-customer
parameters:
customer: [email protected]"customers": [
{
"custId": 1,
"firstName": "Merilyn",
"lastName": "Bayless",
"companyName": "20 20 Printing Inc",
"addresses": [
{
"address": "195 13n N",
"city": "Santa Clara",
"county": null,
"state": "CA",
"zip": "95054"
}
],
"phones": [
{
"mobile": "408-758-5015",
"office": "408-758-5015"
}
],
"email": "[email protected]",
"web": "http://www.printinginc.com",
"region": "US West",
"customerType": "Silver",
"jobTitle": "Project Manager",
"logo": null
},Where and how to use datasources
In a Global file
Datasources are defined once and are available throughout your solution to be reused in multiple jigs. Adding a global datasource improves performance as the data is retrieved once rather than multiple times.

Open your solution in Jigx Builder and navigate to the datasources folder of your solution.
Create a new file called <your_datasource_name>.jigx.
Invoke IntelliSense (ctrl+space) for the list of available datasources.
Select the datasource you want to use and configure the properties with values. When choosing Dynamic Dataor SQL data, you can write SQL queries to return the data you want to use in the solution.
Next, open the jigs where you want to use the data, use expressions with the datasource option to reference the global datasource file, for example,
[email protected].
Local within a jig
The data sets are defined in the datasources inside the individual jig generally under the datasources: property. Use datasources locally if you only need the data in that specific jig.

Open your solution in Jigx Builder and navigate to the jig.
Under the
datasources:property, replaces themydata:property with a unique name for the data set.Invoke IntelliSense (ctrl+space) next to the
mydata:property for the list of available datasources.Select the datasource you want to use and configure the properties with values. When choosing Dynamic Data or SQL data, you can write SQL queries to return the data you want to use in the jig. Tip: only return the specific data you need in the datasource.
The data is now available to use in that jig by using expressions with the datasource option to reference the local datasource using the unique name you gave it, for example,
[email protected].
See Also
Last updated
Was this helpful?