DataTables can be joined on on a single column to create a new DataTable with the combined columns and rows from each matching the records on the fields specified in the join method. Note, the join's on method returns a DataTable because there is no other transform option. There is no need to call a separate table method to create the table.


var dtSales = new eb.data.DataTable([ 
    {productId: "001", sales: 100},
    {productId: "002", sales: 200},
    {productId: "003", sales: 300}
]);
 
var dtProduct = new eb.data.DataTable([ 
    {Id: "001", Name: "apples"},
    {Id: "002", Name: "oranges"},
    {Id: "003", Name: "bananas"}
]);
 
 
// join the sales and product data tables
var table = dtSales.join(dtProduct).on("productId", "Id");
 
// create a new table from a subset of the fields
table = table.select().column("Name").as("Product").column("sales").table();



The leftJoin method returns all rows from the left table with the matching rows in the right table. The result is null on the right side when there is no match.


var dtMovies = new eb.data.DataTable([ 
    {id: "01", title: "Office Space"},
    {id: "02", title: "Caddyshack"},
    {id: "03", title: "Animal House"}
]);
 
var dtMovieComments = new eb.data.DataTable([ 
    {id: "01", comment: "I have a case of the Monday's"},
    {id: "02", comment: "Kill all the golfers?"}
]);
 
 
// join the tables - second column reference not needed as they have the same name
var table = dtSales.leftJoin(dtProduct).on("id");
 
// create a new table from a subset of the fields
table = table.select("title", "comment").table();