Multiple datatables, single data source.

I have a local JS array with multiple types of objects. I want to have a data table for each type of object (filtered by the type: “objecttype” value of each object). How would i filter each data table to only show objects for a specific object type.

Pseudo Example

// Array of objects.

myArray= [{type: car…}, {type: boat…}, {type: airplane…}]

// Datatables.

carDatatable.data/collection = objects of myArray of type car.

boatDatatable.data/collection = objects of myArray of type boat.

airplaneDatatable.data/collection = objects of myArray of type airplane.

I could create multiple arrays from the myArray, or a multi-dimensional array. But i don’t want that. I want all data tables to have the same source.

var source = [...];
var table1 = $$("table1");
var table2 = $$("table2");
table1.sync(source, function() {
   this.filter(function(data){
      return data.type === 'car';
   });
}, true);
table2.sync(source, function() {
   this.filter(function(data){
      return data.type === 'boat';
   });
}, true);

Thank you intergral :slight_smile:

Could i ask how you manage to format code like you do in this forum

simply put your code between two ~~~

Daring Fireball: Markdown Syntax Documentation
Markdown Editing Help - Stack Overflow

Awesome, thanks a bunch.