Summing up in a DataGrid column

There is a DataGrid element and a database is connected to it. The database has a column with the type “decimal”. There is no way to sum up such a column in the DataGrid (as I understand it). I decided to put the calculation under the DG. How to write the formula correctly? I tried it this way

, but it doesn’t work.

Is this a dynamic value I.e can be updated by the user on the fly or always the sum of all those values in the collection array?

The amount should change when a new line is added.

Your path is incorrect, it seems that there is a “payload” structure

Is it working on your datagrid?

I will advise updating your collection so that the data are what’s inside payload, and not an object with a key payload and data inside

Like this?


I’m experimenting. Since Directual’s Front is weak, I do it in Weweb. Connected via Rest API.

No, on the collections settings itself.
The first argument of sum need tl be an array or a collection.
But a collection is normally returning an array. When you define your collection, (i suppose here its a rest api collection) you can define a key to get the data (payload here).
You should see your collection display correctly on the right after that (on the collection panel)

On the first screenshot, the first argument is Collection. I don’t quite understand how to determine the key, Directual doesn’t have such a function. you mean this one?


Or did I misunderstand?

Can you help me?

On your last screenshot, you can see a result_key field. This should be set to payload on the collection you displayed on your first message.

I’m not quite sure how this helps me, I have a text field underneath the DataGrid. I need it to display the sum of one of the columns in the table. Or did I get it wrong?

Hi.
And yet, back to my question. How to summarize the data?

Hi @icos :wave:

Can you try this:

sum(rollup(Budget Exp.data.payload[0],"summ_expens")) (Note: I don’t think this will work if you copy/paste it from here but it should work if you write the formula in WeWeb)

This is what’s happening

  • rollup(Budget Exp.data.payload[0],"summ_expens") will return all the values of “summ_expens”
  • then if you wrap a sum around it, all those values should be summed

Does that do the trick for you?

1 Like

Finally, it worked).
Thank you so much, Joyce.

1 Like