title: list
type: jig.list
icon: delete
header:
type: component.jig-header
options:
height: medium
children:
type: component.image
options:
source:
uri: https://images.unsplash.com/photo-1531545514256-b1400bc00f31?q=80&w=1374&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D
onFocus:
type: action.action-list
options:
isSequential: true
actions:
- type: action.sync-entities
options:
provider: DATA_PROVIDER_DYNAMIC
entities:
- default/employee
datasources:
employee-list:
# the SQLite datasource calls the Dynamic Data provider, writing a SQL query returns the data from the provider to the jig
type: datasource.sqlite
options:
provider: DATA_PROVIDER_DYNAMIC
# specify the table in Dynamic Data that you want to work with
entities:
- default/employee
query: SELECT
id,
'$.first_name',
'$.last_name',
'$.job_title',
'$.email',
'$.start_date',
'$.department',
'$.contact'
FROM
[default/employee]
data: =@ctx.datasources.employee-list
item:
type: component.list-item
options:
title: =(@ctx.current.item.first_name & ' ' & @ctx.current.item.last_name)
subtitle: =@ctx.current.item.job_title
swipeable:
right:
- label: Delete
icon: delete-2
color: negative
onPress:
type: action.execute-entity
options:
provider: DATA_PROVIDER_DYNAMIC
entity: default/employee
method: delete
data:
id: =@ctx.current.item.id
onSuccess:
type: action.go-back
# add a button to the list to detete all records
actions:
- children:
- type: action.confirm
options:
style:
isDanger: true
title: Delete ALL employees
isConfirmedAutomatically: false
onConfirmed:
type: action.execute-entities
options:
# execute the delete method of the Dynamic Data provider, use the datasource in the expression to specific all ids to delete
provider: DATA_PROVIDER_DYNAMIC
entity: default/employee
method: delete
# Cater for offline data handling to add the delete command to the queue.
# Once the device is back online the queue is cleared and the delete
# command executes. Do not use replace as the queue is cleared without
# executing the delete method.
queueOperation: add
data: =@ctx.datasources.employee-list.{"id" :id}[]
onSuccess:
type: action.go-back
# Deleting all data is irreversible, use a modal to confirm the delete before actually executing the delete
modal:
title: Are you sure you want to delete ALL?