Updating calculated column when ordering.

Updating calculated column when ordering.

amimusamimus Posts: 5Questions: 1Answers: 0

Hi,
I have a problem updating calculated column when ordering.
My HTML is composed from :
an Input text
a table with (3) three columns, titled respectively , column1, column2, column3.
the value of column3 in each row will be: the input text value from witch I subtract the sum of column2 value in all previous rows including the current row.
My issue is : when I order my table, let's say based on column1, I want to update column3 following the same logic as described above. the values in column3 aren't calculated as they should.
this is my JsFiddle to reproduce the case : https://jsfiddle.net/rgzk097b/62/.
Any suggestions!
Thanks.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @animus,

    The columns.render is the wrong place for that, you need to do the sums in drawCallback, that way it'll always be right for the rows being displayed.

    Cheers,

    Colin

  • amimusamimus Posts: 5Questions: 1Answers: 0

    Hi @colin,
    Thank you for the answer.
    I adjusted the code as you suggested.
    It works to compute the right values. however the values in column3 are inverted.
    I don't see the reason.
    Here is my JsFiddle updated : https://jsfiddle.net/rgzk097b/62/
    Thanks!

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @amimus ,

    I think you forgot to update the link - that one doesn't have the drawCallback . Happy to take a look if you can double check that link.

    Cheers,

    Colin

  • amimusamimus Posts: 5Questions: 1Answers: 0

    Hi @colin
    Sorry!
    Here is the updated link : https://jsfiddle.net/rgzk097b/64/
    Thanks.

  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    Answer ✓

    Hi @amimus ,

    See updated version here. The problem is because the code wasn't getting the rows in the current order,

    Cheers,

    Colin

  • amimusamimus Posts: 5Questions: 1Answers: 0
    edited October 2018

    Thanks a lot @colin! You are Great!
    That terminates 3 days of frustration.
    The best way to start my office day.
    Thanks again!
    Have a nice day!

This discussion has been closed.