Client-Side Data View, get total of a field on filtered records

Hey guys,

I have hard time finding this…

I have a Data View (coming form a ServerConnect) in my page and I want to get a total form a field BUT at the same time I need to set conditions.

For example:
I need to pull the total amount of orders but only form the records that order_Status=='PENDING"
(I want to use the same DataView data in various places in my page, it is a dashboard page)

I can just create as many instances of the DataView I need and set the filter on each DataView according to my needs. (that’s what I did)

But I’m just wondering if we could use client-side formatters to get the desired results

Any ideas would be much appreciated,

Thanks in advance

Hi there @famousmag

I just let the query output all the orders without any aggregates (sums), then use a couple of set values in the Server Action to add up what I need:

order_Total = orders.sum('ord_Total')
order_Total_Pending = orders.where('ord_Status', '==', 'PENDING').sum('ord_Total')

You are best to do it on the server side, as the client side formatters can really slow down the GUI.

I hope that helps!

Antony.

1 Like

Thanks @Antony for replying!!

So, let me learn a few new things now… :wink:

  1. It is better to calculations on server side instead of client-side?
    I always had in mind that if (in a high-traffic site) 100 users are on-line performing the same task it would be harder than pass the task to each user’s terminal…

  2. Something like that is what I had in mind for client-side but the formatters wasn’t available there

Anyway, thanks a lot for your suggestions, I will try to have them in mind!!
:+1:

Hi there @famousmag

Pleasure!

  1. I believe server side is always better.

  2. Those formatters are on the client side too!

1 Like

You’re right @Antony … It works if I hand code it (because after applying the where formatter, the sum formatter comes just with no parameter but I added by hand)


But only in ServerConnect…
The same statement doesn’t work for the DataView…

Here is the output:

Yes, the .where() has different formatting on the client side…