Adding results sum (for a field)

44 views
Skip to first unread message

Andrea Borruso

unread,
Aug 24, 2011, 9:58:08 AM8/24/11
to simile-...@googlegroups.com
Hi all,
I'm sure this a simple task, but I do not find a solution.

I would like to add in the header of my exhibit html file, the results sum for a specified numeric field. What kind of object I must add?
I know there is "add" function, but I do not know how to write the snippe of code necessary to view the sum of field values for all filtered records.

Thank you,

a

Axel Hecht

unread,
Aug 25, 2011, 7:00:18 AM8/25/11
to simile-...@googlegroups.com
I'd start with reverse-engineering http://code.google.com/p/simile-widgets/source/browse/exhibit/trunk/src/webapp/api/scripts/ui/widgets/collection-summary-widget.js.

Axel

2011/8/24 Andrea Borruso <abor...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "SIMILE Widgets" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simile-widgets/-/nG_MZaKeQd4J.
To post to this group, send email to simile-...@googlegroups.com.
To unsubscribe from this group, send email to simile-widget...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simile-widgets?hl=en.

Andrea Borruso

unread,
Aug 25, 2011, 7:17:50 AM8/25/11
to simile-...@googlegroups.com
Hi Axel,
thank you.

I'm sure the code you link solves my problem, but I do not know how to use it. Some pratical advice for me?

Thank you again,

a

Axel Hecht

unread,
Aug 25, 2011, 7:51:03 AM8/25/11
to simile-...@googlegroups.com
Doodled around a bit:

c=exhibit._uiContext.getCollection()
_s=Exhibit.ExpressionParser.parse('add( .unchanged )');
_s.evaluate({value:c.getRestrictedItems()},{value:'item'},'value',exhibit._database).values.toArray()

and you wanna refresh that in a listener like this:

c.addListener({onItemsChanged:function(){ console.log(_s.evaluate({value:c.getRestrictedItems()},{value:'item'},'value',exhibit._database).values.toArray())}})

Axel

2011/8/25 Andrea Borruso <abor...@gmail.com>


a

--
You received this message because you are subscribed to the Google Groups "SIMILE Widgets" group.
To view this discussion on the web visit https://groups.google.com/d/msg/simile-widgets/-/TmT3QUyzX8wJ.

Antonio Falciano

unread,
Aug 25, 2011, 7:43:35 AM8/25/11
to simile-...@googlegroups.com
Il 25/08/2011 13.17, Andrea Borruso ha scritto:
> Hi Axel,
> thank you.
>
> I'm sure the code you link solves my problem, but I do not know how to
> use it. Some pratical advice for me?

Hi all,

@Andrea: the "add" snippet is missing here [1]. However it's quite
intuitive to reconstruct. Suppose you have three fields you want to sum
together (e.g. .a, .b and .c). The sum missing snippet would be:

<div ex:content="add(.a, .b, .c)"></div>

I have tested this function successfully in this working example [2] (see at
row 110) that you know quite well. ;)

Cheers,
Antonio

[1] http://simile.mit.edu/wiki/Exhibit/2.0/Functions
[2]
http://dl.dropbox.com/u/1583841/TANTO/where_to_sleep_in_turin/where_to_sleep_in_turin_add.htm

--
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano

Reply all
Reply to author
Forward
0 new messages