niiknow / vue-datatables-net

Vue jQuery DataTables.net wrapper component
https://niiknow.github.io/vue-datatables-net/
MIT License
171 stars 58 forks source link

Footer column sums #47

Closed TychaK closed 2 years ago

TychaK commented 3 years ago

There's no available documentation on how to add the footer callback with sums.

noogen commented 3 years ago

Documentation for that is not here since everything can be done on the jquery datatables.net side. See their documentation, maybe specifically here - https://datatables.net/plug-ins/api/sum()

gwachhamit commented 3 years ago

Adding this callback in options object does not work why.

 "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
            var total = api.column( 3, { search: 'applied'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
            // Update footer
          console.log(api);
            $( api.column( 3 ).footer() ).html(total);
        },

But testing in jsfiddle works very much fine. I've added also, The above lines should replace the 3rd footer column with with the total value, But it doesnot work but while using console.log(total) it gives the total correctly. Seems the problem is in vue component side of the datatable. Help me

noogen commented 2 years ago

Stale issue.