footerCallback

footerCallback

dozedoze Posts: 5Questions: 1Answers: 0
edited July 2014 in Free community support

http://live.datatables.net/heyuyos/1/ (Preview)
http://live.datatables.net/heyuyos/1/edit (Edit)

can someone help..
what i want is that the total in my footer will not compute the rows with a status of withdraw only the Paid ons should be computed..
i really have no idea how to do that coz im a beginner in js.. thanks ^_^

Answers

  • dozedoze Posts: 5Questions: 1Answers: 0

    bump!
    anyone?

  • dozedoze Posts: 5Questions: 1Answers: 0

    WEW i was able to do it at last
    iknow the code sucks but anyone is welcome to clean my code.
    that would be awesome and addition to my knowledge thanks ^_^

    $(document).ready( function () {
      var table = $('#example').DataTable({
      "footerCallback": function(row, data, start, end, display) {
                    
                        var api = this.api();
                        var intVal = function(i) {
                            return typeof i === 'string' ?
                                    i.replace(/[\$,]/g, '') * 1 :
                                    typeof i === 'number' ?
                                    i : 0;
    
                        };
    
    totalRows = api.column(0).data().length;
    total=0;
    for (i = 0; i < totalRows; ++i) {
        if(api.columns(6).data()[0][i]=='Paid'){
            total += intVal(api.columns(5).data()[0][i]);
        }
    }
    total = total.toFixed(3);
    
        
        
                      data = api.column(5, {page: 'current'}).data();
                      Currenttotal=0;
                       for (i = 0; i < data.length; i++) {
                         if(api.columns(6, {page: 'current'}).data()[0][i]==='Paid'){
                         Currenttotal += intVal(api.columns(5, {page: 'current'}).data()[0][i]);
                         }
                       }
                      pageTotal=Currenttotal;
                               
    
        
                   
        
    
    
                        // Update footer
                        $(api.column(5).footer()).html(
                                '<b style="color:red;">CurrentPage: P' + pageTotal + '</b> <br><i><b>( AllPage: P' + total + ' total)</b></i>'
                                );
                    
    
                }
      });
      
    } );
    
This discussion has been closed.