Datasources
8 min
datasources are sets of data used in jigx solutions and are used to reference data from the various data providers docid\ hi5nkisjutyk6mkml7la6 types there are three types of datasources available in jigx builder sqlite using the sqlite datasource provides the ability to write sql queries to get data from dynamic data and local data providers for code examples and snippets, see sqlite https //docs jigx com/examples/sqlite 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 https //docs jigx com/examples/static system the system datasource is used to get a list of icons for jig components for code examples and snippets, see system https //docs jigx com/examples/system configuration options property description code examples 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 https //docs jigx com/examples/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 new contact jigx https //docs jigx com/examples/form#zueja 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 rest best practice docid 1m4jfkkcqjc6djd4nmg1k view customer details jigx https //docs jigx com/examples/list and view customers get#nqfcr isdocument example datasource 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 =@ctx jig inputs contact id json { "contacts" \[ { "id" 1, "firstname" "merilyn", "lastname" "bayless", "companyname" "20 20 printing inc", "phone" "408 758 5015", "email" "merilyn bayless\@cox net", "web" "http //www printinginc com", "jobtitle" "project manager" } ] } form jigx 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 =@ctx jig inputs id children \ type component form instanceid new contact options initialvalues =@ctx datasources contactdata 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 =@ctx components firstname state value lastname =@ctx components lastname state value email =@ctx components email state value phone =@ctx components phone state value jobtitle =@ctx components jobtitle state value companyname =@ctx components companyname state value 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 =@ctx datasources customers item type component list item options title =@ctx current item companyname subtitle =@ctx current item firstname & ' ' & @ctx current item lastname description =@ctx current item addresses\[0] city leftelement element avatar text =@ctx current item addresses\[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 =@ctx current item customertype = 'gold' color color3 \ when =@ctx current item customertype = 'silver' color color14 onpress type action go to options linkto view customer parameters customer =@ctx current item"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" "merilyn bayless\@cox net", "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 global datasource 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, =@ctx datasources employee 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 local datasource open your solution in jigx builder and navigate to the jig under the datasources property, replaces the mydata 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 dataor 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, =@ctx datasources contact see also static https //docs jigx com/examples/static datasource examples sqlite https //docs jigx com/examples/sqlite datasource examples system https //docs jigx com/examples/systemfile handling docid\ ayoldbvzo0bs9jwi u32l