Calculating Column Total for all non-filtered entries

Calculating Column Total for all non-filtered entries

feeredfeered Posts: 6Questions: 0Answers: 0
edited May 2012 in General
Basically what the discussion title states: I need to calculate 3 columns total for all non filtered items; not just what's on the DOM.

I found this topic: http://datatables.net/forums/discussion/823/calulating-totals-for-multiple-columns-through-fnfootercallback/p1

I broke it down into this

[code]
"fnFooterCallback": function (nRow, aasData, iStart, iEnd, aiDisplay ) {
if(iEnd > 0) { // if search result is empty do nothing
var column=[8, 9, 10]; //the columns you wish to add
for(var j in column) {
var total=0;
for(var i=iStart;i

Replies

  • allanallan Posts: 63,546Questions: 1Answers: 10,476 Site admin
    Have a look at this plug-in which has the options that I think you want: http://datatables.net/plug-ins/api#fnGetColumnData :-)

    Allan
  • feeredfeered Posts: 6Questions: 0Answers: 0
    edited May 2012
    Great! This is what I was looking for. The only problem I am having now is getting the fnGetColumnData to work properly on fnDrawCallBack.

    I want the total to update on fnDrawCallBack but the issue is, is that it seems that the table initializes before the plugin is processed. So in my console, I am receiving that fnGetColumnData does not exist. I tried using $.isFunction( oTable.fnGetColumnData ) but I don't think I am using that right.

    Any suggestions?
  • feeredfeered Posts: 6Questions: 0Answers: 0
    edited May 2012
    Okay, so it wasn't the plugin that wasn't initializing incorrectly.. Matter of fact, everything was initializing correctly. It was the fact fnDrawCallback is executed even when the table isn't fully initialized.. Maybe a sanity check is required to ensure that fnDrawCallBack is only called when all DataTable elements are initialized.

    For now, I did:
    [code]
    if ( typeof oTable == 'undefined' ) return;
    [/code]
  • allanallan Posts: 63,546Questions: 1Answers: 10,476 Site admin
    Actually - it can be quite useful to use fnDrawCallback when the table is still initialising (manipulating the DOM for example). For this reason (at least, this is one of the reasons) the callback functions are executed in the instances' scope. So to access an API method you can simply use the 'this' keyword. For example: this.fnGetNodes() .

    Allan
This discussion has been closed.