Error Sum Table Footer

Error Sum Table Footer

rafaswrafasw Posts: 78Questions: 7Answers: 0
edited December 2019 in Free community support

I'm having trouble adding the sum

My Full Code

$(document).ready(function() {

      var advance = $('#advanced-table').DataTable( {
  dom: 'Blfrtip',

  mark: true,
    buttons: {
        name: 'primary',
        buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print' ]
    },
    
          //"language": {
                //"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json"
           // } 
          
    "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
 
            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
 
            // Total over all pages
            total = api
                .column( 5 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            // Total over this page
            pageTotal = api
                .column( 5, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            // Update footer
            $( api.column( 5 ).footer() ).html(
                'R$'+pageTotal +' ( R$'+ total +' Value Total)'
            );
        }
    } );

    
    
 

// Setup - add a text input to each footer cell
    $('#advanced-table tfoot th').each( function () {
        
  
        
    } );
      // Apply the search
 advance.columns().every( function () {
    
        var title = $(this.footer()).text();
    $(this.footer()).html( '<div class="md-input-wrapper"><input type="text" class="md-form-control" placeholder=" '+title+'" /></div>' );
     
        var that = this;
        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that.search( this.value ).draw();
            }
        } );
    } );

    

    } );

Error Print Image

following my code above how to add a value at all equal to this image

thanks

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Make sure you have a tfoot for your table. If you do and its still not working then post a test case as asked for by Colin.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0
  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    You are overwriting the footer with your code building the search inputs. Here is an example of placing the search inputs into the header that doesn't affect the footer:
    http://live.datatables.net/giharaka/1/edit

    Note the use of orderCellsTop to place the ordering functions in the top header.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    I used the code you passed me but it didn't work

    http://live.datatables.net/fomidaqo

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Removed this from your CSS:

     tfoot {
        display: table-header-group;
    }
    

    And added a second thead. Looks like it works now:
    http://live.datatables.net/fomidaqo/2/edit

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    Even making this change is not showing the total without footer and the search for separate fields also stopped working

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    I must have posted the wrong link. Here is the updated example with those two changes:
    http://live.datatables.net/timeboka/1/edit

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    Doesn't work when i move to the original file doesn't work

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Doesn't work when i move to the original file

    Do you mean the test case you provided or on your system?

    What exactly is not working? Without seeing it its hard to say since the problem is specific to your code. Maybe you can update your test case to show the issue and provide the new link. Make sure you remove that footer CSS.

    KEvin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0
    edited December 2019
  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Please provide the steps to get to your table.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    just click the link that I put that goes straight to the table
    http://encurtador.com.br/cryCV

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Sorry, I don't see a table. I see this:

    Kevin

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921
    edited December 2019

    You still have this in your main.css file:

    }
     tfoot {
        display: table-header-group;
    }
    

    Which is removing your footer.

    You haven't added the second header. I noted this above and have done the same in the example I posted:
    http://live.datatables.net/timeboka/1/edit

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0
    edited December 2019
          tfoot {
            display: table-header-group;
         } 
    

    removed just went downstairs but a separate field search still doesn't work

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    separate field search still doesn't work

    What isn;'t working? Do the search inputs show or is the search not working?

    Doesn't look like you updated the test case link you provided.

    Kevin

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Please provide a link to a test case, or your page, with steps on how to reproduce your issue, and an explanation of what you would expect to see instead.

    Colin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    I update css yes and update java script so separate search fields don't work

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    I took a look at the link you provided earlier and don't see those changes. Please update the test case so we can take a look.

    Kevin

This discussion has been closed.