Things I have tried
Read Dataview documentation, googled and also searched in this forum and did not found this specific case.
What I’m trying to do
I’m wandering how can we group rows in dataviewjs table when our source is a array of custom objects.
This is a small example of what I have:
let myArray = [];
// Lets say I can not get my objects directly from my notes. So I build them in a for loop based on the notes.
let obj1 = { type: "a", value: 10 };
myArray.push(obj1);
let obj2 = { type: "b", value: 50 };
myArray.push(obj2);
let obj3 = { type: "a", value: 20 };
myArray.push(obj3);
// So I get to put this array of custom objects in a table
dv.table(["Type", "Value"], myArray.map(a => [a.type, a.value]));
Now, instead of just show all values in the table, how would I group by “type” in order to have the sum of “value” for each group?
If i just try to add a group by clause I get an error message like “myArray.groupBy is not a function”.
This is how I tryed:
dv.table(["Type", "Value"], myArray.groupBy(g => g.type).map(a => [a.key, a.rows.length]));