You are viewing limited content. For full access, please sign in.

Question

Question

Forms table remove line refresh

asked on November 15, 2016

I have built a line item table for a customer using the Laserfiche samples for Total etc.  I have simplified it for this question.

The calculation is correct when I add a new row.  However if I delete a row the Total keeps its previous value.  That is, the Total still includes the deleted row.

If I click into the table it will change.

Is there any way I can get the total to automatically update after a line deletion?  It would appear that Forms does not count this as a "change".

Perhaps a refresh button?

$(document).ready(function () {


  $('.itemsAUD').on('blur', 'input', linetotal);

    function linetotal() {
        var sum = 0;
        $('.cf-table-block tbody tr').each(function () {
            var s = 0;
            s = parseNumber($(this).find('.qty input').val()) * parseNumber($(this).find('.unitprice input').val());
            $(this).find('.linetotal input').val(s.toFixed(2));
            sum += s;
       });

        $(".total input").val(sum.toFixed(2));

    }
  
    function parseNumber(n) {
        var f = parseFloat(n);
        return isNaN(f) ? 0 : f;
    }
});

Table with two rows:

Table with second line removed; the Total is incorrect:

 

0 0

Answer

SELECTED ANSWER
replied on November 15, 2016 Show version history

It actually quite easy, i use it all the time, but you do need v10.1.

To sum or calculate in table rows the formula uses INDEX(tableNAME.Columnname.ROW ()) to represent a row item in a table. You put a total column in the row and then put this in the advance Calc area of the field.

An example of adding two columns in a table would be.

=SUM(INDEX(TABLENAME.COLUMNNAME1,ROW ()), TABLENAME.COLUMNNAME2,ROW ()))

You can also muliply, div, etc.

When you add or remove rows they take care of themselves.

Then to total all the rows you do a normal =SUM(columnname) into you grand total field outside the table.

0 0

Replies

replied on November 17, 2016

Steve, please refer to this post for a solution to stopping the line total from calculating without all the line values.

https://answers.laserfiche.com/questions/110762/Error-in-table-when-calculating-Line-Total

I used:

=IF(AND( INDEX(Table.Qty,ROW())>0,INDEX(Table.Price,ROW())>0),(PRODUCT( INDEX(Table.Qty,ROW()) , INDEX(Table.Price,ROW()))),0)

1 0
replied on November 15, 2016

Have you considered updating to forms 10.1 where you can use the inherent Forms Calculations instead of JS to provide this functionality?

0 0
replied on November 15, 2016

Thanks Steve,

But as mentioned this sample is a simplified version of what I have to create.  I don't have the knowledge to create the real version in Form Calculations.

Complete table:

0 0
SELECTED ANSWER
replied on November 15, 2016 Show version history

It actually quite easy, i use it all the time, but you do need v10.1.

To sum or calculate in table rows the formula uses INDEX(tableNAME.Columnname.ROW ()) to represent a row item in a table. You put a total column in the row and then put this in the advance Calc area of the field.

An example of adding two columns in a table would be.

=SUM(INDEX(TABLENAME.COLUMNNAME1,ROW ()), TABLENAME.COLUMNNAME2,ROW ()))

You can also muliply, div, etc.

When you add or remove rows they take care of themselves.

Then to total all the rows you do a normal =SUM(columnname) into you grand total field outside the table.

0 0
replied on November 15, 2016

Thanks Steve, I will try it out.  I could not find much in Laserfiche for this.  Is there a better reference? 

0 0
replied on November 15, 2016 Show version history

Formulas are bases on the Oasis Open Standard and Excel. LF has yet to update their help files for all of the 70 functions they have added.

Fyi, found a syntax error in the formula above. It was ,ROW not .Row

0 0
replied on November 15, 2016

Thanks Steve. Much appreciated

0 0
replied on November 16, 2016

Attached is a form Template as an example for you, just rename the file from .txt to .xml to be able to import into your Form as a Business Process.

Includes Calc for the Total and an IF statement for the Tax as per the picture you had posted.

0 0
replied on November 16, 2016

I have used the formula for Line Total:   "=PRODUCT( INDEX(Purchases.Qty,ROW()) , INDEX(Purchases.Unit_Price,ROW()) )".

The formula works OK but it gives the Line Total the Quantity value when only the Quantity is set.  This cascades down to the Total Amount.  I have set Qty and Price to 'Required' but it still looks a bit odd.

Also I have been using the formula for Line Total:

"= INDEX(Line_Items.Qty,ROW()) * INDEX(Line_Items.Price,ROW())"

but this will show an error at the Line Total as soon as the Quantity is entered as it is trying to multiply a value by a blank field.  I will address this in another post.

Thanks again for your help.

 

 

0 0
replied on November 16, 2016

Hi Peter, yes, if you use ×, /, etc you may see errors when the formula are incomplete, its how they have implemwnted the error correct, but if you use the other formulas such as Product(var1,var2) or DIV (var1,var2) they work correctly.

Yes, the formulas do calculate on the fly, some people chose to put default values in the fields (ie:0) or move the Qty field next to the prixe so it is filled in after the text, just symantics but some prefer it that way.

0 0
replied on November 16, 2016

I did not like the defaults as they can add extra keystrokes for the user.

I have now set the total fields to "hidden" until the Qty and Price have values > 1.

 

0 0
replied on January 10, 2017 Show version history

Your code formats the result to two decimal places, which is a reason for using Javascript instead of a Laserfiche formula to calculate the total. In order to make your javascript work after a line has been deleted, add a line that says:

  $('.itemsAUD').on('click', linetotal);

Your complete script will then be:

$(document).ready(function () {


  $('.itemsAUD').on('blur', 'input', linetotal);
  $('.itemsAUD').on('click', linetotal);

    function linetotal() {
        var sum = 0;
        $('.cf-table-block tbody tr').each(function () {
            var s = 0;
            s = parseNumber($(this).find('.qty input').val()) * parseNumber($(this).find('.unitprice input').val());
            $(this).find('.linetotal input').val(s.toFixed(2));
            sum += s;
       });

        $(".total input").val(sum.toFixed(2));

    }
  
    function parseNumber(n) {
        var f = parseFloat(n);
        return isNaN(f) ? 0 : f;
    }
});

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.