DataTables have methods that allow the data and structures in the table to be managed.


New Rows


Use newRow and insert to add new rows to a table. Note, calculated columns will automatically be calculated when using this method to add data to a table.


var table = new eb.data.DataTable([ 
    {product: "apples", order: "PRN001", quantity: 10},
    {product: "oranges", order: "PRN002", quantity: 15},
    {product: "apples", order: "PRN003", quantity: 20}    
]);
 
// add a calculated column
table.addColumn("Calculated Column").calc(function(row){
    return row["quantity"] * 2;
});
 
// generate a new empty row that has the table schema
var row = table.newRow();
 
// set product and quantity but leave other fields empty
row["product"] = "pears";
row["quantity"] = 30;
 
// insert can take a single row or an array of rows
var rows = [row];
table.insert(rows);
 
table.insert(row);

// set the second parameter to insert at the top of the rows collection
table.insert(row, true);


Update Rows


Use the update method to update data tables with new data.


// update all rows in the product column to "jello"
table.update().set("product").value("jello");
 
...
 
// increase all quantity rows by 20%
table.update().set("quantity").calc(function(row) {
    return row["quantity"] * 1.2;
});



Delete Rows


Use the delete method to delete rows from a table.


// delete all rows where product is equal to "apples"
table.delete().eq("product", "apples");
 
...
 
// delete all rows where product is not equal to "apples"
table.delete().ne("product", "apples");
 
...
 
// delete all rows where product is equal to "apples" using a custom formula
table.delete().calc(function(row, index, table) {
    return row["product"] == "apple";
});