Displaying totals in dataform

Displaying totals in dataform

by Louise Bennett -
Number of replies: 4

I'm not sure this is even possible, but I have to ask!

I am basically attempting to use the dataform as a spreadsheet; each student fills out as many rows as they are required, and it totals the value of each row. I have that working fine - it looks great. 

What I would also like to do, however, is have a second view that will simply display, for each student, the total value of all the rows they've put in. The formula works, but obviously, dataform is designed to display multiple entries. I can get it to show my total, but it shows it as many times as there are entries. If I try and show only 1 entry, it only totals the single row, rather than all rows added by the student.. 

Is there a way to do what I'm trying to do? It's cool if there's not, but I have to try!

Attachment total.png
Attachment total2.png
Average of ratings: -
In reply to Louise Bennett

Re: Displaying totals in dataform

by Itamar Tzadok -

Should students see others' totals?

If not then you can filter the designated personal total view on current user and then when a student opens the view he/she will see only his/her total. If you put the total formula in the View template of this designated view (rather than the entry template), the total will show only once. You can also populate this total to the main list view either by adding a dataform_view block to the page of the main list view, or by adding to the view template of the main list view the pattern ##viewcontent:<the personal total view name>##.

If you want the view to show totals for all students and you're ok with css3 you can try using :nth-of-type(). In the Entry template, set the css class of the container of the total formula with the entry author id, hide it, and add a style definition to show the first. The following example should show for each student one row with the student name and sum total of number*cost from all the student's entries (note missing square brackets):

<div style="display:none;>%%F[EAU:id]:=[!number]*[!cost]%%</div>
<div class="total[EAU:id]">[EAU:name]: $ %%F:=sum(_F[EAU:id]_)%%</div>
<style>
div.total[EAU:id] {display:none};
div.total[EAU:id]:ntn-of-type(1) {display:block};
</style>

Haven't tried it yet so if you try please let me know how it worked.

hth smile

In reply to Itamar Tzadok

Re: Displaying totals in dataform

by Louise Bennett -

Oh! I didn't even think of filtering, or putting the total formula in the view template. Brilliant!

Thank you so much!

In reply to Itamar Tzadok

Re: Displaying totals in dataform

by Noah Freedman -

Just tried this.  The calculations worked perfectly.

However, the styling was harder.  I couldn't work out how to stop TinyMCE from deleting the div <style>.  In the end, I had to put it into the Dataform css tab.

Also, instead of:

div.<classname> {display:none};
div.<classname>:ntn-of-type(1) {display:block};

which didn't work, I used

.<classname>:nth-of-type(n+2) {display:none};

which did!

In reply to Noah Freedman

Re: Displaying totals in dataform

by Itamar Tzadok -

Yes, the editor doesn't like inline styles but it doesn't mind class names. The easiest way to hide an element is to use the core class 'hide', as in:

<div class="hide">...</div>

hth smile