can you display aggregations in a template?

  • 1
  • Question
  • Updated 4 years ago
  • Answered
  • (Edited)
I feel like I'm missing something obvious here...can you display an aggregation in a template field?  It works just fine if I place the aggregate field in the Field Editor but I can't get it to display in a template.  

Any help would be greatly appreciated!
Photo of Gary Bailey

Gary Bailey

  • 1,628 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Peter Baeza

Peter Baeza

  • 2,868 Points 2k badge 2x thumb
If you use it in a field editor you get the model context automatically. If you have a template outside of a field editior I think you need to specfify the model context fully. For example if you have a model aggModel with a summary aliased sumAmount,

In the field editor you could use {{sumAmount}} in a template
Outside of the field editor you could use {{$Model.aggModel.data.0.sumAmount}}
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Just a slight clarification to Peter's post: you need to use an Aggregation / Grouping field's Alias Name in the template, for instance if your aggregation is SUM(Amount), and the alias name is sumAmount, then in the template you must say {{sumAmount}} or {{{sumAmount}}} , rather than {{Amount}} and {{{Amount}}}.
Photo of Gary Bailey

Gary Bailey

  • 1,628 Points 1k badge 2x thumb
That worked!  Just for clarification, to display the aggregation in the template I formatted it as follows:

{{$Model.NewlyMatched_aggr.data.0.countNewlyMatched}}


Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Perfect.  I'm totally going to steal that picture. 
Photo of Joe Ort

Joe Ort

  • 2,256 Points 2k badge 2x thumb
How can you add up all rows of an aggregate model to display in a template?  I have a dashboard working but I need to display a number in a template from an aggregate model that has groupings.

I tried to leverage this but am not at all a javascript person.

How could I add up all rows of "OppyAggregate" model's "sumNCVIc" (alias)?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
We have not exposed the API for column summaries.  Sorry.  This means the solutions discussed in the link above are really not relevant to your use case.  What I do to satisfy this requirement is create a separate aggregate model that doesn't have the grouping for the single total number.  
Photo of Joe Ort

Joe Ort

  • 2,256 Points 2k badge 2x thumb
Is there a way to have one table filter both models then?  I'd like to have filters at the top allowing people to dig into the data in different ways and present the updated numbers.

Thanks,
Joe

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Take a look at Pat's post from a few days ago:  https://console.getsatisfaction.com/skuid/conversations/cross-model-linked-conditions

Does exactly what you are looking for...