Data
The most common configuration feature when working with third-party components is data-binding. WireBootstrap components are bound with data using the data configuration parameter. This parameter can be set to any number of standard data structures.

Data

In the example below, the component is bound to an array of objects.
1
const users = [
2
{ value: "jkratz", label: "Jamie Kratz" },
3
{ value: "pdougherty", label: "Pat Dougherty" }
4
];
5
6
const select = new wire.bsSelect().render("#select", {
7
data: users
8
});
Copied!
Components can also be data bound to a WireBootstrap DataTable.
1
const userTable = new wire.data.DataTable([
2
{ value: "jkratz", label: "Jamie Kratz" },
3
{ value: "pdougherty", label: "Pat Dougherty" }
4
]);
5
6
const select = new wire.bsSelect().render("#select", {
7
data: userTable
8
});
Copied!

DataMap

Many components require a specific set of fields in order to render data. A chart for example will need to know which fields to use to render the axis labels as well as which ones contains the metric data to plot on the chart.
The Bootstrap Select component expects the data passed in to contain a field called value and another called label. If these field names don't exist in the data, use the datamap attribute to specify which fields should be used.
In the example below, the UserName field in the data is to be used as the value field and the FullName field as the label field.
1
const users = [
2
{ UserName: "jkratz", FullName: "Jamie Kratz" },
3
{ UserName: "pdougherty", FullName: "Pat Dougherty" }
4
];
5
6
const select = new wire.bsSelect().render("#select", {
7
data: users,
8
datamap: { value: "UserName", label: "FullName" }
9
});
Copied!

DataRow

Some components require a single record. Use datarow to specify the row in the data if it contains more than one row. This is a zero index reference.
In the following example, the component will be bound to the second rowFred Flintstone.
1
const users = [
2
{ value: "Barney Rubble" },
3
{ value: "Fred Flintstone" }
4
]
5
6
const input = new wire.bsInput().render("#input", {
7
data: users,
8
datarow: 1
9
});
Copied!

DataSet

Binding a component to a WireBootstrap DataSet allows the component to be updated with new data whenever a field in its query is changed.
1
const accountService = new wire.data.DataSource("table", {
2
Provider: {
3
Server: "query-server"
4
}
5
});
6
7
const query = wire.data.select("UserName", "FullName").from("Users");
8
9
const dataset = new wire.data.DataSet({
10
Source: accountService,
11
Query: query
12
});
13
14
const select = new wire.bsSelect().render({
15
data: dataset,
16
datamap: { value: "UserName", label: "FullName" }
17
});
Copied!

DataConfig

When using a dataset as data for a component, custom data can be passed to the Transform method using the dataconfig property. This can be helpful in custom shaping the resulting datatable sent to the UI after a data service call.
1
const dataset = new wire.data.DataSet({
2
...
3
Transform: (data, callback) => {
4
5
let table = data.table;
6
7
if (data.config.removeFred) {
8
table.delete().eq("value", "Fred Flintstone").table();
9
}
10
11
callback(table);
12
13
}
14
});
15
16
...
17
18
const input = new wire.bsInput().render("#input", {
19
data: dataset,
20
dataconfig: { removeFred: true },
21
});
Copied!

Data Method

Especially helpful when using a data set, the data method can be used to pull the actual data being displayed in the component. In the case of a dataset, this will usually be a data table returned from a data service.
1
...
2
3
const select = new wire.bsSelect().render({
4
data: dataset,
5
datamap: { value: "UserName", label: "FullName" }
6
});
7
8
...
9
10
const datatable = select.data();
Copied!