Data Events
A dataset listens for changes to elements of their queries using data events. For example, if a data set finds a change to a query field with the same name sent out in a data event, its able to change its query, re-execute it in the data service, and update its data promises so UI components and other consumers can react to the change.
In the following example, any data event sent out for the field UserName by dsFilter will be picked up by dsTable as a change and result in dsTable re--executing its query based on the change. dsTable will then update its promises with new data.
1
...
2
3
const dsFilter = new wire.data.DataSet({
4
Events: false,
5
Source: source1,
6
Query: wire.data.select("UserName")
7
.from("Users")
8
});
9
10
const dsTable = new wire.data.DataSet({
11
Source: source2
12
Query: wire.data.select("UserName", "FullName")
13
.from("Employees")
14
});
Copied!
Note, dsFilter.Events is set to false as most filters don't need to listen for changes.
Also, each dataset uses a different data source. They don't have to be the same.

Event Names

Consider the following two datasets on the same page bound to two different UI components. Both the entity and field names are not the same however the intent is that data in dsFilter be used to change the query in dsTable.
However, sometimes its not possible to set up two queries inside datasets to share field changes by name because their names are different in the respective data services.
Fields from different database tables or entirely different data services can be mapped to be recognized as the same by the data event manager using the field or parameter alias EventName.
In the following example, the field method is used to select the UserName field in dsTable in order that meta data like eventName be set on the field. An event name UserName is set on the User field in the dsTable query in order for it to be mapped to the field UserName in dsFilter for the purposes of picking up changes via data events.
1
...
2
3
const dsFilter = new wire.data.DataSet({
4
Events: false,
5
Source: source1,
6
Query: wire.data.select("UserName")
7
.from("Users")
8
});
9
10
const dsTable = new wire.data.DataSet({
11
Source: source2
12
Query: wire.data.select("FullName")
13
.field("User").eventName("UserName")
14
.from("Employees")
15
});
Copied!
Copy link
Contents
Event Names