running totals and accessing other rows from meta

running totals and accessing other rows from meta

jasonblewisjasonblewis Posts: 3Questions: 2Answers: 0

Hi,

I'm trying to make a running total column in a table.

A solution I came up with accesses the value of a cell in the previous row using:

meta.settings.aoData[meta.row-1].anCells[3].innerText

but this seems a little hacky, is there a better way?

code here:
http://codepen.io/jasonblewis/pen/egVPNP?editors=0010

any advice would be appreciated.

Answers

  • vincellcvincellc Posts: 10Questions: 3Answers: 0

    Jason, thanks for the workaround. I'm trying to do the same thing using

    cell(meta.row-1, meta.column).data()

    but the value is returned empty.

  • allanallan Posts: 61,732Questions: 1Answers: 10,110 Site admin

    The settings object is considered to be private and thus shouldn't be accessed externally.

    There are a couple of issues with using aoData[ meta.row - 1]:

    1. It won't work with sorting
    2. It won't work with filtering.

    There is basically no good way to do a running total with the rendering callback.

    I think a better approach would be something like the index column example - although obviously with a summation of data rather than just a counter.

    Allan

  • meskimeskimeskimeski Posts: 7Questions: 4Answers: 0

    Allan - can you please show more example or little bit more explain how to make with index column

  • allanallan Posts: 61,732Questions: 1Answers: 10,110 Site admin

    Happy to create an example under the support 60 package.

    Allan

  • vol7ronvol7ron Posts: 43Questions: 11Answers: 0

    This is old question, reminded me of my DataTables post, which I think turned into a GitHub pull request

    It contains an example I created of a running subtotal (row groups):
    http://live.datatables.net/sajaxota/6/edit

    I know I had other versions that posted the full total and, but I don't have any available online. For anyone else coming to this post, maybe this will lead you in a possible direction for calculating totals

This discussion has been closed.