1

I'm not at all a software developer and I need to know how can I average a set of values of one row in a DotNetNuke table inside of Form and List Module. I have tried using this for the expression:

'AVG('+[Num1]+','+[Num2]+','+[Num3]+')'

but this only returns concatenated: AVG(10,20,30) after I set the values of 10,20,30.

Anyone ideas?

    $(document).ready(function() 
    { $("#budgetWorksheet tbody tr").change(rowAverage); });
    function rowAverage() { var totalAvg = 0; $("tbody tr").slice(0,-1).each(function()
    { var row_total = 0; var i = "td:not(.subtotal)                                    input:text",                       
    this).each(function() { row_total +=      parseInt(this.value || 0, 10);  
    }).length; if (row_total > 0) { var avg =  Math.floor(parseInt(row_total, 10) /  
    i); $(".subtotal input:text", this).val(avg);  totalAvg += avg; } });
    $(.totalAvg input").val(totalAvg); 
user2158328
  • 53
  • 1
  • 6

1 Answers1

1

You will likely need to use XSLT to do this, FnL supports XSL templates, you can create them and apply them in the configuration for the module.

Doing it with the standard Grid layout would likely be a little more difficult, but could probably be done through jQuery. Here's a SO question that does some jQuery to figure out averages https://stackoverflow.com/questions/8812548/sum-table-row-text-fields-with-running-overall-total-in-text-field

Community
  • 1
  • 1
Chris Hammond
  • 8,873
  • 1
  • 26
  • 34
  • Hey, thank you very much for your reply! I went to create the XSL template but I don't know where to insert the code from your link. Please help and thanks again. – user2158328 Mar 14 '13 at 13:59
  • Let me try to be more specific: I clicked to create a new template which then has XML code tags. I tried inserting the aforementioned piece of code on the bottom of that window below all the XML code and I get an error. – user2158328 Mar 14 '13 at 16:00
  • You might try posting the XSL that you generate here so people can look at it. – Chris Hammond Mar 16 '13 at 14:22
  • $(document).ready(function() { $("#budgetWorksheet tbody tr").change(rowAverage); }); function rowAverage() { var totalAvg = 0; $("tbody tr").slice(0,-1).each(function() { var row_total = 0; var i = $("td:not(.subtotal) input:text", this).each(function() { row_total += parseInt(this.value || 0, 10); }).length; if (row_total > 0) { var avg = Math.floor(parseInt(row_total, 10) / i); $(".subtotal input:text", this).val(avg); totalAvg += avg; } }); $(".totalAvg input").val(totalAvg); } – user2158328 Mar 18 '13 at 13:29
  • I'm sorry, not sure how to format the above to make it look better. – user2158328 Mar 18 '13 at 13:30
  • Put it into the question (update the question) and use the CODE formatting – Chris Hammond Mar 19 '13 at 04:32