I am unable to do the Sum for column Amount which is having the data like - values.
I am unable to do the Sum for column Amount which is having the data like - values.
Saritha
Posts: 23Questions: 7Answers: 1
Please suggest me how to the Sum for Column at footer level.Its kind of urgency and please suggest me how to achieve the same.
j$ = jQuery.noConflict(); j$(document).ready( function () { //here i am applying the Datatable for my list in salesforce var ordermtdTable = j$('[id$="ordertable"]').DataTable({ }); });This question has accepted answers - jump to:
This discussion has been closed.
Answers
You are going to want to do something very similar to https://datatables.net/examples/api/multi_filter_select.html except instead of adding select input, you are summing up the column values.
If not all the columns are to be summed up, you can qualify within the https://datatables.net/reference/api/columns()
Hello i want something like this in below link
https://datatables.net/examples/advanced_init/footer_callback.html
Total needs to be calculate at footer level.
and this code is not working to me.Suggest me any solution with example code samples
If you have tried the code in the linked example and it doesn't work for you, then we would need to see a working example with your code in order to help debug.
Please see DataTables Live
The below is the code i am using for this.
j$ = jQuery.noConflict(); j$(document).ready( function () { var ordermtdTable = j$('[id$="ordertable"]').DataTable({ "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 ) { console.log('enter1'); return typeof i === 'string' ? i.replace(/[\$,]/g, '')*1 : typeof i === 'number' ? i : 0; }; // Total over all pages total = api .column( 6 ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Total over this page pageTotal = api .column( 6, { page: 'current'} ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Update footer $( api.column( 6 ).footer() ).html( '$'+pageTotal +' ( $'+ total +' total)' ); } } ); } ); }); });Declared th footer:
<tfoot>
<tr>
<th colspan="6" style="text-align:right">Total:</th>
<th></th>
</tr>
</tfoot>
and included the javasript tags in header
Here is a working example
Make sure your column # is correct. Column index starts with 0.
Thank you all.
It is working as expected.Please let me know is there any chance like wanted to display only the grant total and not required the Total of the page.
Yes - the example you linked to above shows how you can sum over all columns, not just the current page.
Allan
Every thing looks fine,i have modified the footer logic only to display the total value of all pages.
I have the field with negative values and sorting is not working for that particular field.
Please suggest what are can be scenarios to solve this
Output is like below:
-31643.8
-3500
-854.38
-944.62
10000
13.05
157.44
157
We'd need a link to the page showing the issue so it can be debugged please. If you can't link to the page, you can use JSFiddle, CodePen or similar to create a test case showing the issue.
Allan