Rows
A WireBootstrap data table contains methods for maintaining the objects inside an array of data. This array can accessed directly via the Rows property on a data table.

Add Rows

The newRow method on a data table will return an empty row with the same schema as the existing rows. Each of the values will be null.
Below product and quantity values are set on a new row and inserted into the table using the insert method.
1
let table = new eb.data.DataTable([
2
{product: "apples", order: "PRN001", quantity: 10},
3
{product: "oranges", order: "PRN002", quantity: 15},
4
{product: "apples", order: "PRN003", quantity: 20}
5
]);
6
7
let row = table.newRow();
8
9
row["product"] = "pears";
10
row["quantity"] = 30;
11
12
table.insert(row);
Copied!
The insert method on the data table can also take an array of rows and will by default add them to the end of the array of existing rows. Passing true in as the second parameter will add them to the top of the array.
1
let rows = [];
2
3
...
4
5
table.insert(rows, true);
Copied!

Update Rows

The example below updates the product column for all rows in the data table to jello using the update method.
1
...
2
3
table.update("product", "jello");
Copied!
The following example uses custom logic via the calc function with update to increase all quantity rows by 20%.
1
...
2
3
table.update("quantity").calc((row) => {
4
return row["quantity"] * 1.2;
5
});
Copied!

Delete Rows

The example below deletes all rows where product is equal to apples using the delete method.
1
...
2
3
table.delete().eq("product", "apples");
Copied!
The example does the same thing using custom logic in the boolean calc function.
1
...
2
3
table.delete().calc((row) => {
4
return row["product"] == "apple";
5
});
Copied!
For more on maintaining rows in a data table, visit the DataTables reference page.