You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I have been playing with row formulas for couple of days. db-folder is fantastic.
I created a function to calculate the number of elements that are selected in a relation column and got something like this:
function numElements(col) {
dv = app.plugins.plugins.dataview.api;
flattened = dv.array(col);
// console.log(flattened)
let i = 0
flattened.forEach(elem => {
i = i + 1;
})
return i;
}
module.exports = numElements;
The relation column lec_tur_rel looks like something like this:
Row 1 contains two tutorials; row 2 contains 2 tutorials; and row 3 contains three.
The formula in the column NumTutorials is ${db.js.numElements(row["lec_tut_rel"])}.
The formula works fine; I get the results I need. But when I print the results to the console.log it seems that the formula is running as many times as the number of rows, which seems to be correct but inefficient. You may think you could this simpler by using the formula ${row["lec_tut_rel"].length}, but it will not work; it will only return the number of elements in the relation of the first row, and the rest of the rows will be empty.
help wantedExtra attention is neededtriageIssue not tagged yet. talking to the user
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have been playing with row formulas for couple of days. db-folder is fantastic.
I created a function to calculate the number of elements that are selected in a relation column and got something like this:
The relation column
![image](https://user-images.githubusercontent.com/19330646/228624757-1a6fefa6-f10d-4e6b-bcc9-fa49bcffba4c.png)
lec_tur_rel
looks like something like this:Row 1 contains two tutorials; row 2 contains 2 tutorials; and row 3 contains three.
The formula in the column
NumTutorials
is${db.js.numElements(row["lec_tut_rel"])}
.The formula works fine; I get the results I need. But when I print the results to the console.log it seems that the formula is running as many times as the number of rows, which seems to be correct but inefficient. You may think you could this simpler by using the formula
${row["lec_tut_rel"].length}
, but it will not work; it will only return the number of elements in the relation of the first row, and the rest of the rows will be empty.Could someone recommend a better function?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions