footerCallback does not compute sum for a fixedColumn when filter is applied

footerCallback does not compute sum for a fixedColumn when filter is applied

mj0sephmj0seph Posts: 7Questions: 2Answers: 0

Hello!

I would like to compute a column's sum (Salary, in this case) which is (1) also a fixedColumn and (2) subject to any applied filtering. In this example, I've commented the fixedColumn options out demonstrating that the filtered salaries' sum is computed as expected. However, when the fixedColumn options are applied (Name and Salary columns, in this case) the footerCallback sum reflects the total of all salaries regardless of filtering.

Any advice or thoughts on alternative approaches are appreciated!

live.datatables.net/peheboke

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590
    Answer ✓

    Hi @mj0seph ,

    You can call fixedColumns().update() whenever the table is drawn, see here - this ensures the fixedColumns' layer gets updated with the new information.

    I had expected that I could do this in the footerCallback, but for some reason that's causing an error. I've raised it internally (DD-1180 for my reference) and we'll report back here when there's an update.

    For the meantime, the draw should do the trick as shown above.

    Cheers,

    Colin

  • mj0sephmj0seph Posts: 7Questions: 2Answers: 0

    Thanks, @colin ! That worked perfectly. I appreciate your quick and helpful response.

  • martoomartoo Posts: 5Questions: 1Answers: 0

    Ok how did you make that work? Is there a bug when the fixed column is not the only one? I have this:
    "fixedColumns": {
    "leftColumns": "7",
    },
    And sums are requred for columns after 5 and it does not update on draw. Can you tell me how to fix it?

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    @martoo please see my answer in your other thread.

    Kevin

This discussion has been closed.