in Education by
I want to make a table to be able to help me make price comparisons. Explanations: In my table I have: Project Product Manufacturer Title Quantity Unit buying price (sum) Total price buying (sum) Multiply (average) Unit sales price (sum) Total sales price (sum) Profit (sum) The ideal in my case would be to select the lines I want to keep to see the total price of my choices. So I can see the cost of different options. someone would have an idea or have already encountered this problem? Thank you for helps :) EDIT the sum for each columns work fine, but when i don't find how to have only the sum for each columns when i select them. Sorry but i am not comfortable with js :-/ // 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; }; $(document).ready(function() { var table = $('#example').DataTable( { columnDefs: [{ targets: [4,5,6,8,9,10], render: $.fn.dataTable.render.number(',', '.', 2) }], responsive: true, paging:false, "footerCallback": function ( row, data, start, end, display ) { var api = this.api(), data; var sumColumns = [4,5,6,8,9,10]; sumColumns.forEach(function(colIndex){ // Total over all pages var total = api .rows({ selected: true }) .column(colIndex) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Total over this page var pageTotal = api .column(colIndex, { page: 'current'} ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 ); // Update footer $( api.columns(colIndex).footer() ).html( total ); }) }, }); });

Contacts

projectid productid manufacturerid title quantity PAU a PAT a Coef a PVU a PVT a Profit a
1 5 5 Title 1 10 130 1300 2 260 2600 1300
2 3 6 Title 2 10 100 1000 2 200 2000 1000
3 2 5 Title 3 10 50 500 2 100 1000 500
PAU a PAT a PVU a PVT a Profit a
Run code snippetExpand snippet JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I wrote a function to calculate your columns and the average for the 7th column, this is separate from your code, you can use it anywhere that you want. jQuery(document).ready(function($) { var sumColumns = [4,5,6,8,9,10]; $.each(sumColumns, function(index, val) { var total = 0; jQuery('tbody tr td:nth-child('+val+')').each(function(index, el) { total += parseInt($(this).html()); }); jQuery('tfoot tr th:nth-child('+val+')').each(function(index, el) { $(this).html(total); }); }); var total = 0; jQuery('tbody tr td:nth-child(7)').each(function(index, el) { total += parseInt($(this).html()); }); jQuery('tfoot tr th:nth-child(7)').each(function(index, el) { $(this).html(total/jQuery('tbody tr td:nth-child(7)').length); }); });

Related questions

0 votes
    I'm making a simple star rating feature in PHP to my site and my general question is, do cookies ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I'm making a simple star rating feature in PHP to my site and my general question is, do cookies ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm making a simple star rating feature in PHP to my site and my general question is, do cookies ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I have Html website. There is newsletter signup form in the html. It is processed by php script file ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have Html website. There is newsletter signup form in the html. It is processed by php script file ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have Html website. There is newsletter signup form in the html. It is processed by php script file ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I need to sum some rows applying on each row a formula and after all sum in a last column all ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    I need to sum some rows applying on each row a formula and after all sum in a last column all ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    In _______________ index instead of storing all the columns for a record together, each column is stored ... topic in portion Indexing and Hashing of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    __________ is used when you have variables that form rows instead of columns. (a) tidy() (b) spread() (c ... Analysis of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    I want to bind two data frames with different set of columns and I also want to retain all the columns that fails to ... do that in R? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I have some long data I need to convert into a wide fixed width text format. I have a large ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I am trying to figure out how to pull only specific rows and columns using Google apps script. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    A __________ is a set of elements appearing in rows and columns where the elements are of the same mode whether ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    ___________ provides optional labels with the columns and rows. (a) Disnames (b) Dimnames (c) Denmes (d) ... Out of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
...